From a672f7d553ac17d5aaef8dc667dee31d5815677d Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Tue, 19 Mar 2019 19:14:17 +0000 Subject: 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 --- src/term/mod.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/term') 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) -> Point; /// Find the nearest URL boundary in both directions. - fn url_search(&self, _: Point) -> Option; + fn url_search(&self, _: Point) -> Option; } 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) -> Option { + fn url_search(&self, mut point: Point) -> Option { // 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 { &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), -- cgit