aboutsummaryrefslogtreecommitdiff
path: root/src/grid/mod.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-03-19 19:14:17 +0000
committerGitHub <noreply@github.com>2019-03-19 19:14:17 +0000
commita672f7d553ac17d5aaef8dc667dee31d5815677d (patch)
tree0289e3deb60e3fdce6025fded1ec9c3299bc893d /src/grid/mod.rs
parenteb7a1ea803ba54d3b8cd6af49255eb8fbe0d7544 (diff)
downloadalacritty-a672f7d553ac17d5aaef8dc667dee31d5815677d.tar.gz
alacritty-a672f7d553ac17d5aaef8dc667dee31d5815677d.zip
Add URL hover highlighting
This changes the cursor whenever it moves to a cell which contains part of a URL. When a URL is hovered over, all characters that are recognized as part of the URL will be underlined and the mouse cursor shape will be changed. After the cursor leaves the URL, the previous hover state is restored. This also changes the behavior when clicking an illegal character right in front of a URL. Previously this would still launch the URL, but strip the illegal character. Now these clicks are ignored to make sure there's no mismatch between underline and legal URL click positions
Diffstat (limited to 'src/grid/mod.rs')
-rw-r--r--src/grid/mod.rs60
1 files changed, 22 insertions, 38 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index 837d9b0e..c555400d 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -17,7 +17,7 @@
use std::cmp::{min, max, Ordering};
use std::ops::{Deref, Range, Index, IndexMut, RangeTo, RangeFrom, RangeFull};
-use crate::index::{self, Point, Line, Column, IndexRange};
+use crate::index::{self, Point, Line, Column, IndexRange, PointIterator};
use crate::selection::Selection;
mod row;
@@ -105,14 +105,6 @@ pub struct Grid<T> {
max_scroll_limit: usize,
}
-pub struct GridIterator<'a, T> {
- /// Immutable grid reference
- grid: &'a Grid<T>,
-
- /// Current position of the iterator within the grid.
- pub cur: Point<usize>,
-}
-
#[derive(Copy, Clone)]
pub enum Scroll {
Lines(isize),
@@ -587,7 +579,7 @@ impl<T> Grid<T> {
pub fn iter_from(&self, point: Point<usize>) -> GridIterator<'_, T> {
GridIterator {
grid: self,
- cur: point,
+ point_iter: point.iter(self.num_cols() - 1, self.len() - 1),
}
}
@@ -602,43 +594,28 @@ impl<T> Grid<T> {
}
}
+pub struct GridIterator<'a, T> {
+ point_iter: PointIterator<usize>,
+ grid: &'a Grid<T>,
+}
+
+impl<'a, T> GridIterator<'a, T> {
+ pub fn cur(&self) -> Point<usize> {
+ self.point_iter.cur
+ }
+}
+
impl<'a, T> Iterator for GridIterator<'a, T> {
type Item = &'a T;
fn next(&mut self) -> Option<Self::Item> {
- let last_col = self.grid.num_cols() - Column(1);
- match self.cur {
- Point { line, col } if line == 0 && col == last_col => None,
- Point { col, .. } if
- (col == last_col) => {
- self.cur.line -= 1;
- self.cur.col = Column(0);
- Some(&self.grid[self.cur.line][self.cur.col])
- },
- _ => {
- self.cur.col += Column(1);
- Some(&self.grid[self.cur.line][self.cur.col])
- }
- }
+ self.point_iter.next().map(|p| &self.grid[p.line][p.col])
}
}
impl<'a, T> BidirectionalIterator for GridIterator<'a, T> {
fn prev(&mut self) -> Option<Self::Item> {
- let num_cols = self.grid.num_cols();
-
- match self.cur {
- Point { line, col: Column(0) } if line == self.grid.len() - 1 => None,
- Point { col: Column(0), .. } => {
- self.cur.line += 1;
- self.cur.col = num_cols - Column(1);
- Some(&self.grid[self.cur.line][self.cur.col])
- },
- _ => {
- self.cur.col -= Column(1);
- Some(&self.grid[self.cur.line][self.cur.col])
- }
- }
+ self.point_iter.prev().map(|p| &self.grid[p.line][p.col])
}
}
@@ -669,6 +646,13 @@ impl<T> IndexMut<index::Line> for Grid<T> {
}
}
+impl<T> IndexMut<usize> for Grid<T> {
+ #[inline]
+ fn index_mut(&mut self, index: usize) -> &mut Row<T> {
+ &mut self.raw[index]
+ }
+}
+
impl<'point, T> Index<&'point Point> for Grid<T> {
type Output = T;