aboutsummaryrefslogtreecommitdiff
path: root/src/term/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/term/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/term/mod.rs')
-rw-r--r--src/term/mod.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs
index fd31cd5e..09f45721 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -20,6 +20,7 @@ use std::time::{Duration, Instant};
use arraydeque::ArrayDeque;
use unicode_width::UnicodeWidthChar;
+use glutin::MouseCursor;
use font::{self, Size};
use crate::ansi::{self, Color, NamedColor, Attr, Handler, CharsetIndex, StandardCharset, CursorStyle};
@@ -30,10 +31,9 @@ use crate::grid::{
use crate::index::{self, Point, Column, Line, IndexRange, Contains, Linear};
use crate::selection::{self, Selection, Locations};
use crate::config::{Config, VisualBellAnimation};
-use crate::MouseCursor;
use copypasta::{Clipboard, Load, Store};
use crate::input::FONT_SIZE_STEP;
-use crate::url::UrlParser;
+use crate::url::{Url, UrlParser};
use crate::message_bar::MessageBuffer;
use crate::term::color::Rgb;
use crate::term::cell::{LineLength, Cell};
@@ -54,7 +54,7 @@ pub trait Search {
/// Find the nearest semantic boundary _to the point_ of provided point.
fn semantic_search_right(&self, _: Point<usize>) -> Point<usize>;
/// Find the nearest URL boundary in both directions.
- fn url_search(&self, _: Point<usize>) -> Option<String>;
+ fn url_search(&self, _: Point<usize>) -> Option<Url>;
}
impl Search for Term {
@@ -70,11 +70,11 @@ impl Search for Term {
break;
}
- if iter.cur.col == last_col && !cell.flags.contains(cell::Flags::WRAPLINE) {
+ if iter.cur().col == last_col && !cell.flags.contains(cell::Flags::WRAPLINE) {
break; // cut off if on new line or hit escape char
}
- point = iter.cur;
+ point = iter.cur();
}
point
@@ -92,9 +92,9 @@ impl Search for Term {
break;
}
- point = iter.cur;
+ point = iter.cur();
- if iter.cur.col == last_col && !cell.flags.contains(cell::Flags::WRAPLINE) {
+ if point.col == last_col && !cell.flags.contains(cell::Flags::WRAPLINE) {
break; // cut off if on new line or hit escape char
}
}
@@ -102,7 +102,7 @@ impl Search for Term {
point
}
- fn url_search(&self, mut point: Point<usize>) -> Option<String> {
+ fn url_search(&self, mut point: Point<usize>) -> Option<Url> {
// Switch first line from top to bottom
point.line = self.grid.num_lines().0 - point.line - 1;
@@ -1143,8 +1143,7 @@ impl Term {
&self.grid
}
- // Mutable access for swapping out the grid during tests
- #[cfg(test)]
+ /// Mutable access to the raw grid data structure
pub fn grid_mut(&mut self) -> &mut Grid<Cell> {
&mut self.grid
}
@@ -2034,15 +2033,15 @@ impl ansi::Handler for Term {
ansi::Mode::CursorKeys => self.mode.insert(mode::TermMode::APP_CURSOR),
ansi::Mode::ReportMouseClicks => {
self.mode.insert(mode::TermMode::MOUSE_REPORT_CLICK);
- self.set_mouse_cursor(MouseCursor::Arrow);
+ self.set_mouse_cursor(MouseCursor::Default);
},
ansi::Mode::ReportCellMouseMotion => {
self.mode.insert(mode::TermMode::MOUSE_DRAG);
- self.set_mouse_cursor(MouseCursor::Arrow);
+ self.set_mouse_cursor(MouseCursor::Default);
},
ansi::Mode::ReportAllMouseMotion => {
self.mode.insert(mode::TermMode::MOUSE_MOTION);
- self.set_mouse_cursor(MouseCursor::Arrow);
+ self.set_mouse_cursor(MouseCursor::Default);
},
ansi::Mode::ReportFocusInOut => self.mode.insert(mode::TermMode::FOCUS_IN_OUT),
ansi::Mode::BracketedPaste => self.mode.insert(mode::TermMode::BRACKETED_PASTE),