■ ■ ■ ■ ■ ■
alacritty_terminal/src/term/mod.rs
skipped 357 lines 358 358 res += self 359 359 .line_to_string(line, start.column..end.column, start.column.0 != 0) 360 360 .trim_end(); 361 + res += "\n"; 362 + } 361 363 362 - // If the last column is included, newline is appended automatically. 363 - if end.column != self.columns() - 1 { 364 - res += "\n"; 365 - } 366 - } 367 364 res += self.line_to_string(end.line, start.column..end.column, true).trim_end(); 368 365 }, 369 366 Some(Selection { ty: SelectionType::Lines, .. }) => { skipped 1649 lines 2019 2016 } 2020 2017 2021 2018 #[test] 2019 + fn simple_selection_works() { 2020 + let size = SizeInfo::new(5., 5., 1.0, 1.0, 0.0, 0.0, false); 2021 + let mut term = Term::new(&Config::default(), size, ()); 2022 + let grid = term.grid_mut(); 2023 + for i in 0..4 { 2024 + if i == 1 { 2025 + continue; 2026 + } 2027 + 2028 + grid[Line(i)][Column(0)].c = '"'; 2029 + 2030 + for j in 1..4 { 2031 + grid[Line(i)][Column(j)].c = 'a'; 2032 + } 2033 + 2034 + grid[Line(i)][Column(4)].c = '"'; 2035 + } 2036 + grid[Line(2)][Column(0)].c = ' '; 2037 + grid[Line(2)][Column(4)].c = ' '; 2038 + grid[Line(2)][Column(4)].flags.insert(Flags::WRAPLINE); 2039 + grid[Line(3)][Column(0)].c = ' '; 2040 + 2041 + // Multiple lines contain an empty line. 2042 + term.selection = Some(Selection::new( 2043 + SelectionType::Simple, 2044 + Point { line: Line(0), column: Column(0) }, 2045 + Side::Left, 2046 + )); 2047 + if let Some(s) = term.selection.as_mut() { 2048 + s.update(Point { line: Line(2), column: Column(4) }, Side::Right); 2049 + } 2050 + assert_eq!(term.selection_to_string(), Some(String::from("\"aaa\"\n\n aaa "))); 2051 + 2052 + // A wrapline. 2053 + term.selection = Some(Selection::new( 2054 + SelectionType::Simple, 2055 + Point { line: Line(2), column: Column(0) }, 2056 + Side::Left, 2057 + )); 2058 + if let Some(s) = term.selection.as_mut() { 2059 + s.update(Point { line: Line(3), column: Column(4) }, Side::Right); 2060 + } 2061 + assert_eq!(term.selection_to_string(), Some(String::from(" aaa aaa\""))); 2062 + } 2063 + 2064 + #[test] 2022 2065 fn semantic_selection_works() { 2023 2066 let size = SizeInfo::new(5., 3., 1.0, 1.0, 0.0, 0.0, false); 2024 2067 let mut term = Term::new(&Config::default(), size, ()); skipped 63 lines 2088 2131 } 2089 2132 2090 2133 #[test] 2091 - fn selecting_empty_line() { 2092 - let size = SizeInfo::new(3 .0 , 3 .0 , 1.0, 1.0, 0.0, 0.0, false); 2134 + fn block_selection_works() { 2135 + let size = SizeInfo::new(5 ., 5 ., 1.0, 1.0, 0.0, 0.0, false); 2093 2136 let mut term = Term::new(&Config::default(), size, ()); 2094 - let mut grid: Grid<Cell> = Grid::new(3, 3, 0); 2095 - for l in 0 ..3 { 2096 - if l != 1 { 2097 - for c in 0..3 { 2098 - grid[Line(l)][Column(c)].c = 'a'; 2099 - } 2137 + let grid = term.grid_mut(); 2138 + for i in 1 ..4 { 2139 + grid[Line(i)][Column(0)].c = '"'; 2140 + 2141 + for j in 1..4 { 2142 + grid[Line(i)][Column(j)].c = 'a'; 2100 2143 } 2144 + 2145 + grid[Line(i)][Column(4)].c = '"'; 2101 2146 } 2147 + grid[Line(2)][Column(2)].c = ' '; 2148 + grid[Line(2)][Column(4)].flags.insert(Flags::WRAPLINE); 2149 + grid[Line(3)][Column(4)].c = ' '; 2102 2150 2103 - mem::swap(&mut term.grid, &mut grid); 2151 + term.selection = Some(Selection::new( 2152 + SelectionType::Block, 2153 + Point { line: Line(0), column: Column(3) }, 2154 + Side::Left, 2155 + )); 2156 + 2157 + // The same column. 2158 + if let Some(s) = term.selection.as_mut() { 2159 + s.update(Point { line: Line(3), column: Column(3) }, Side::Right); 2160 + } 2161 + assert_eq!(term.selection_to_string(), Some(String::from("\na\na\na"))); 2104 2162 2105 - let mut selection = Selection::new( 2106 - SelectionType::Simple, 2107 - Point { line: Line(0 ), column: Column(0) }, 2108 - Side::Left, 2109 - ); 2110 - selection.update(Point { line: Line(2), column: Column(2) }, Side::Right); 2111 - term.selection = Some(selection); 2112 - assert_eq!(term.selection_to_string(), Some("aaa\n\naaa".into())); 2163 + // The first column. 2164 + if let Some(s) = term.selection.as_mut() { 2165 + s . update ( Point { line: Line(3 ), column: Column(0) }, Side : : Left ) ; 2166 + } 2167 + assert_eq!(term.selection_to_string(), Some(String::from("\n\"aa\n\"a\n\"aa"))); 2168 + 2169 + // The last column. 2170 + if let Some(s) = term.selection.as_mut() { 2171 + s.update(Point { line: Line(3), column: Column(4) }, Side::Right); 2172 + } 2173 + assert_eq!(term.selection_to_string(), Some(String::from("\na\"\na\"\na"))); 2113 2174 } 2114 2175 2115 2176 /// Check that the grid can be serialized back and forth losslessly. skipped 309 lines