aboutsummaryrefslogtreecommitdiff
path: root/src/index.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/index.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/index.rs')
-rw-r--r--src/index.rs77
1 files changed, 70 insertions, 7 deletions
diff --git a/src/index.rs b/src/index.rs
index afeaa271..6dbfbc40 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -17,7 +17,9 @@
/// Indexing types and implementations for Grid and Line
use std::cmp::{Ord, Ordering};
use std::fmt;
-use std::ops::{self, Deref, Add, Range, RangeInclusive};
+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)]
@@ -70,6 +72,67 @@ 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
@@ -312,28 +375,28 @@ macro_rules! ops {
}
}
}
- impl ops::AddAssign<$ty> for $ty {
+ impl AddAssign<$ty> for $ty {
#[inline]
fn add_assign(&mut self, rhs: $ty) {
self.0 += rhs.0
}
}
- impl ops::SubAssign<$ty> for $ty {
+ impl SubAssign<$ty> for $ty {
#[inline]
fn sub_assign(&mut self, rhs: $ty) {
self.0 -= rhs.0
}
}
- impl ops::AddAssign<usize> for $ty {
+ impl AddAssign<usize> for $ty {
#[inline]
fn add_assign(&mut self, rhs: usize) {
self.0 += rhs
}
}
- impl ops::SubAssign<usize> for $ty {
+ impl SubAssign<usize> for $ty {
#[inline]
fn sub_assign(&mut self, rhs: usize) {
self.0 -= rhs
@@ -347,7 +410,7 @@ macro_rules! ops {
}
}
- impl ops::Add<usize> for $ty {
+ impl Add<usize> for $ty {
type Output = $ty;
#[inline]
@@ -356,7 +419,7 @@ macro_rules! ops {
}
}
- impl ops::Sub<usize> for $ty {
+ impl Sub<usize> for $ty {
type Output = $ty;
#[inline]