diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-03-19 19:14:17 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 19:14:17 +0000 |
commit | a672f7d553ac17d5aaef8dc667dee31d5815677d (patch) | |
tree | 0289e3deb60e3fdce6025fded1ec9c3299bc893d /src/event.rs | |
parent | eb7a1ea803ba54d3b8cd6af49255eb8fbe0d7544 (diff) | |
download | alacritty-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/event.rs')
-rw-r--r-- | src/event.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/event.rs b/src/event.rs index 121c0c42..76e7e111 100644 --- a/src/event.rs +++ b/src/event.rs @@ -10,7 +10,7 @@ use std::env; use serde_json as json; use parking_lot::MutexGuard; -use glutin::{self, ModifiersState, Event, ElementState, MouseButton}; +use glutin::{self, ModifiersState, Event, ElementState, MouseButton, MouseCursor}; use copypasta::{Clipboard, Load, Store, Buffer as ClipboardBuffer}; use glutin::dpi::PhysicalSize; @@ -222,6 +222,13 @@ pub enum ClickState { TripleClick, } +/// Temporary save state for restoring mouse cursor and underline after unhovering a URL. +pub struct UrlHoverSaveState { + pub mouse_cursor: MouseCursor, + pub underlined: Vec<bool>, + pub start: Point<usize>, +} + /// State of the mouse pub struct Mouse { pub x: usize, @@ -238,6 +245,7 @@ pub struct Mouse { pub lines_scrolled: f32, pub block_url_launcher: bool, pub last_button: MouseButton, + pub url_hover_save: Option<UrlHoverSaveState>, } impl Default for Mouse { @@ -257,6 +265,7 @@ impl Default for Mouse { lines_scrolled: 0.0, block_url_launcher: false, last_button: MouseButton::Other(0), + url_hover_save: None, } } } |