mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-03 04:34:21 -05:00
Expand line selection across wrapped lines
This commit is contained in:
parent
7dc406252b
commit
7d1edf01c2
3 changed files with 34 additions and 7 deletions
|
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Pressing additional modifiers for mouse bindings will no longer trigger them
|
||||
- Renamed `WINIT_HIDPI_FACTOR` environment variable to `WINIT_X11_SCALE_FACTOR`
|
||||
- Print an error instead of crashing, when startup working directory is invalid
|
||||
- Line selection will now expand across wrapped lines
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -317,14 +317,14 @@ impl Selection {
|
|||
Some(Span { start, end, is_block: false })
|
||||
}
|
||||
|
||||
fn span_lines<T>(term: &T, mut start: Point<isize>, mut end: Point<isize>) -> Option<Span>
|
||||
fn span_lines<T>(term: &T, start: Point<isize>, end: Point<isize>) -> Option<Span>
|
||||
where
|
||||
T: Dimensions,
|
||||
T: Search,
|
||||
{
|
||||
end.col = term.dimensions().col - 1;
|
||||
start.col = Column(0);
|
||||
let start = term.line_search_left(start.into());
|
||||
let end = term.line_search_right(end.into());
|
||||
|
||||
Some(Span { start: start.into(), end: end.into(), is_block: false })
|
||||
Some(Span { start, end, is_block: false })
|
||||
}
|
||||
|
||||
fn span_simple<T>(
|
||||
|
|
|
@ -56,6 +56,10 @@ pub trait Search {
|
|||
fn semantic_search_left(&self, _: Point<usize>) -> Point<usize>;
|
||||
/// Find the nearest semantic boundary _to the point_ of provided point.
|
||||
fn semantic_search_right(&self, _: Point<usize>) -> Point<usize>;
|
||||
/// Find the beginning of a line, following line wraps.
|
||||
fn line_search_left(&self, _: Point<usize>) -> Point<usize>;
|
||||
/// Find the end of a line, following line wraps.
|
||||
fn line_search_right(&self, _: Point<usize>) -> Point<usize>;
|
||||
/// Find the nearest matching bracket.
|
||||
fn bracket_search(&self, _: Point<usize>) -> Option<Point<usize>>;
|
||||
}
|
||||
|
@ -109,6 +113,28 @@ impl<T> Search for Term<T> {
|
|||
point
|
||||
}
|
||||
|
||||
fn line_search_left(&self, mut point: Point<usize>) -> Point<usize> {
|
||||
while point.line + 1 < self.grid.len()
|
||||
&& self.grid[point.line + 1][self.grid.num_cols() - 1].flags.contains(Flags::WRAPLINE)
|
||||
{
|
||||
point.line += 1;
|
||||
}
|
||||
|
||||
point.col = Column(0);
|
||||
|
||||
point
|
||||
}
|
||||
|
||||
fn line_search_right(&self, mut point: Point<usize>) -> Point<usize> {
|
||||
while self.grid[point.line][self.grid.num_cols() - 1].flags.contains(Flags::WRAPLINE) {
|
||||
point.line -= 1;
|
||||
}
|
||||
|
||||
point.col = self.grid.num_cols() - 1;
|
||||
|
||||
point
|
||||
}
|
||||
|
||||
fn bracket_search(&self, point: Point<usize>) -> Option<Point<usize>> {
|
||||
let start_char = self.grid[point.line][point.col].c;
|
||||
|
||||
|
@ -973,7 +999,7 @@ impl<T> Term<T> {
|
|||
tab_mode = true;
|
||||
}
|
||||
|
||||
if !cell.flags.contains(cell::Flags::WIDE_CHAR_SPACER) {
|
||||
if !cell.flags.contains(Flags::WIDE_CHAR_SPACER) {
|
||||
// Push cells primary character
|
||||
text.push(cell.c);
|
||||
|
||||
|
@ -986,7 +1012,7 @@ impl<T> Term<T> {
|
|||
|
||||
if cols.end >= self.cols() - 1
|
||||
&& (line_end == Column(0)
|
||||
|| !self.grid[line][line_end - 1].flags.contains(cell::Flags::WRAPLINE))
|
||||
|| !self.grid[line][line_end - 1].flags.contains(Flags::WRAPLINE))
|
||||
{
|
||||
text.push('\n');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue