diff options
author | Nathan Lilienthal <nathan@nixpulvis.com> | 2019-09-09 16:39:39 -0400 |
---|---|---|
committer | Christian Duerr <contact@christianduerr.com> | 2019-09-09 20:39:39 +0000 |
commit | 86ffa181b342d39f6e2619d371af22951a5a202d (patch) | |
tree | b7049d58f6d5fa4597ccb932466f77b4f5dfa89f /alacritty_terminal/src | |
parent | 20846ef925085e027f99aa37f2e12b597750bdc3 (diff) | |
download | alacritty-86ffa181b342d39f6e2619d371af22951a5a202d.tar.gz alacritty-86ffa181b342d39f6e2619d371af22951a5a202d.zip |
Reset the Mouse Cursor While Selecting
This change disabled the mouse cursor and URL highlight (underline)
while a selection is in progress. A click to clear the selection doesn't
trigger a URL action, but will re-enable the URL highlighting to
indicate the next click will trigger the launcher.
Diffstat (limited to 'alacritty_terminal/src')
-rw-r--r-- | alacritty_terminal/src/input.rs | 37 | ||||
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 2 |
2 files changed, 20 insertions, 19 deletions
diff --git a/alacritty_terminal/src/input.rs b/alacritty_terminal/src/input.rs index b7d1ba05..02d85761 100644 --- a/alacritty_terminal/src/input.rs +++ b/alacritty_terminal/src/input.rs @@ -449,6 +449,8 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { if self.mouse_config.url.mods().relaxed_eq(mods) && (!self.ctx.terminal().mode().intersects(mouse_mode) || mods.shift) && self.mouse_config.url.launcher.is_some() + && self.ctx.selection_is_empty() + && self.ctx.mouse().left_button_state != ElementState::Pressed { let buffer_point = self.ctx.terminal().visible_to_buffer(point); if let Some(url) = @@ -691,34 +693,33 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { self.mouse_report(code, ElementState::Released, modifiers); return; } else if let (Some(point), true) = (point, button == MouseButton::Left) { - self.launch_url(modifiers, point); + let mouse_state = self.mouse_state(point, modifiers); + self.update_mouse_cursor(mouse_state); + if let MouseState::Url(url) = mouse_state { + let url_bounds = url.linear_bounds(self.ctx.terminal()); + self.ctx.terminal_mut().set_url_highlight(url_bounds); + self.launch_url(url); + } } self.copy_selection(); } // Spawn URL launcher when clicking on URLs - fn launch_url(&self, modifiers: ModifiersState, point: Point) -> Option<()> { - if !self.mouse_config.url.mods().relaxed_eq(modifiers) - || self.ctx.mouse().block_url_launcher - { - return None; + fn launch_url(&self, url: Url) { + if self.ctx.mouse().block_url_launcher { + return; } - let point = self.ctx.terminal().visible_to_buffer(point); - let url = self.ctx.terminal().urls().drain(..).find(|url| url.contains(point))?; - let text = self.ctx.terminal().url_to_string(&url); - - let launcher = self.mouse_config.url.launcher.as_ref()?; - let mut args = launcher.args().to_vec(); - args.push(text); + if let Some(ref launcher) = self.mouse_config.url.launcher { + let mut args = launcher.args().to_vec(); + args.push(self.ctx.terminal().url_to_string(url)); - match start_daemon(launcher.program(), &args) { - Ok(_) => debug!("Launched {} with args {:?}", launcher.program(), args), - Err(_) => warn!("Unable to launch {} with args {:?}", launcher.program(), args), + match start_daemon(launcher.program(), &args) { + Ok(_) => debug!("Launched {} with args {:?}", launcher.program(), args), + Err(_) => warn!("Unable to launch {} with args {:?}", launcher.program(), args), + } } - - Some(()) } pub fn on_mouse_wheel( diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 042ad1d0..11e0af45 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -1359,7 +1359,7 @@ impl Term { urls } - pub fn url_to_string(&self, url: &Url) -> String { + pub fn url_to_string(&self, url: Url) -> String { let mut url_text = String::new(); let mut iter = self.grid.iter_from(url.start); |