diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-03-30 09:23:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-30 09:23:48 +0000 |
commit | 91aa683bcd060b2ac2f621a388a6448f564d0537 (patch) | |
tree | 924c9a0759a84be19e397eae8cc28cbd3500d553 /src/index.rs | |
parent | 28636923e02a6cfac0fc950b963623cbcad5fda9 (diff) | |
download | alacritty-91aa683bcd060b2ac2f621a388a6448f564d0537.tar.gz alacritty-91aa683bcd060b2ac2f621a388a6448f564d0537.zip |
Rework URL highlighting
This completely reworks URL highlighting to fix two issues which were
caused by the original approach.
The primary issues that were not straight-forward to resolve with the
previous implementation were about handling the URL highlighted content
moving while the highlight is active.
This lead to issues with highlighting with scrolling and when the
display offset was not 0.
The new approach sticks closely to prior art done for the selection,
where the selection is tracked on the grid and updated whenever the
buffer is rotated.
The truncation of URLs was incorrectly assuming input to be just a
single codepoint wide to truncate the end of URLs with unmatching
closing parenthesis. This is now handled properly using Rust's built-in
Unicode support.
This fixes #2231.
This fixes #2225.
Diffstat (limited to 'src/index.rs')
-rw-r--r-- | src/index.rs | 73 |
1 files changed, 10 insertions, 63 deletions
diff --git a/src/index.rs b/src/index.rs index 6dbfbc40..0004454e 100644 --- a/src/index.rs +++ b/src/index.rs @@ -19,8 +19,6 @@ use std::cmp::{Ord, Ordering}; use std::fmt; use std::ops::{self, Deref, Range, RangeInclusive, Add, Sub, AddAssign, SubAssign}; -use crate::grid::BidirectionalIterator; - /// The side of a cell #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum Side { @@ -72,67 +70,6 @@ impl From<Point> for Point<usize> { } } -impl<T> Point<T> -where - T: Copy + Default + SubAssign<usize> + PartialEq, -{ - pub fn iter(&self, last_col: Column, last_line: T) -> PointIterator<T> { - PointIterator { - cur: *self, - last_col, - last_line, - } - } -} - -pub struct PointIterator<T> { - pub cur: Point<T>, - last_col: Column, - last_line: T, -} - -impl<T> Iterator for PointIterator<T> -where - T: Copy + Default + SubAssign<usize> + PartialEq, -{ - type Item = Point<T>; - - fn next(&mut self) -> Option<Self::Item> { - match self.cur { - Point { line, col } if line == Default::default() && col == self.last_col => None, - Point { col, .. } if col == self.last_col => { - self.cur.line -= 1; - self.cur.col = Column(0); - Some(self.cur) - }, - _ => { - self.cur.col += Column(1); - Some(self.cur) - } - } - } -} - -impl<T> BidirectionalIterator for PointIterator<T> -where - T: Copy + Default + AddAssign<usize> + SubAssign<usize> + PartialEq, -{ - fn prev(&mut self) -> Option<Self::Item> { - match self.cur { - Point { line, col: Column(0) } if line == self.last_line => None, - Point { col: Column(0), .. } => { - self.cur.line += 1; - self.cur.col = self.last_col; - Some(self.cur) - }, - _ => { - self.cur.col -= Column(1); - Some(self.cur) - } - } - } -} - /// A line /// /// Newtype to avoid passing values incorrectly @@ -163,6 +100,16 @@ impl fmt::Display for Column { #[derive(Debug, Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd, Serialize, Deserialize)] pub struct Linear(pub usize); +impl Linear { + pub fn new(columns: Column, column: Column, line: Line) -> Self { + Linear(line.0 * columns.0 + column.0) + } + + pub fn from_point(columns: Column, point: Point<usize>) -> Self { + Linear(point.line * columns.0 + point.col.0) + } +} + impl fmt::Display for Linear { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Linear({})", self.0) |