diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-08-01 15:37:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-01 15:37:01 +0000 |
commit | 9dddf649a15d103295f4ce97b8ae4c178c9623e0 (patch) | |
tree | 609cba8c7eecddc8a2b032e826967bcc04395592 /alacritty_terminal/src/input.rs | |
parent | f51c7b067a05dec7863cca9b8bfaf8329b0cfdfc (diff) | |
download | alacritty-9dddf649a15d103295f4ce97b8ae4c178c9623e0.tar.gz alacritty-9dddf649a15d103295f4ce97b8ae4c178c9623e0.zip |
Switch to rfind_url for URL detection
This switches to rfind_url for detecting URLs inside the grid. Instead
of expanding at the cursor position, the complete terminal is searched
from the bottom until the visible region is left with no active URL.
Instead of having the field `cur` publicly accessibly on the
`DisplayIterator`, there are the two methods `DisplayIterator::point`
and `DisplayIterator::cell` for accessing the current element of the
iterator now. This allows accessing the current element right after
creating the iterator.
Fixes #2629.
Fixes #2627.
Diffstat (limited to 'alacritty_terminal/src/input.rs')
-rw-r--r-- | alacritty_terminal/src/input.rs | 64 |
1 files changed, 13 insertions, 51 deletions
diff --git a/alacritty_terminal/src/input.rs b/alacritty_terminal/src/input.rs index 9443a1a9..8eceef16 100644 --- a/alacritty_terminal/src/input.rs +++ b/alacritty_terminal/src/input.rs @@ -18,27 +18,25 @@ //! In order to figure that out, state about which modifier keys are pressed //! needs to be tracked. Additionally, we need a bit of a state machine to //! determine what to do when a non-modifier key is pressed. +use crate::url::Url; use std::borrow::Cow; use std::mem; -use std::ops::RangeInclusive; use std::time::Instant; use glutin::{ ElementState, KeyboardInput, ModifiersState, MouseButton, MouseCursor, MouseScrollDelta, TouchPhase, }; -use unicode_width::UnicodeWidthStr; use crate::ansi::{ClearMode, Handler}; use crate::clipboard::ClipboardType; use crate::config::{self, Key}; use crate::event::{ClickState, Mouse}; use crate::grid::Scroll; -use crate::index::{Column, Line, Linear, Point, Side}; +use crate::index::{Column, Line, Point, Side}; use crate::message_bar::{self, Message}; use crate::term::mode::TermMode; -use crate::term::{Search, SizeInfo, Term}; -use crate::url::Url; +use crate::term::{SizeInfo, Term}; use crate::util::start_daemon; pub const FONT_SIZE_STEP: f32 = 0.5; @@ -392,15 +390,18 @@ enum MousePosition { impl<'a, A: ActionContext + 'a> Processor<'a, A> { fn mouse_position(&mut self, point: Point) -> MousePosition { + let buffer_point = self.ctx.terminal().visible_to_buffer(point); + + // Check message bar before URL to ignore URLs in the message bar if let Some(message) = self.message_at_point(Some(point)) { if self.message_close_at_point(point, message) { MousePosition::MessageBarButton } else { MousePosition::MessageBar } - // Check for url should be after check for message bar, since we're not looking into - // message bar content. - } else if let Some(url) = self.ctx.terminal().url_search(point.into()) { + } else if let Some(url) = + self.ctx.terminal().urls().drain(..).find(|url| url.contains(buffer_point)) + { MousePosition::Url(url) } else { MousePosition::Terminal @@ -443,7 +444,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { && (!self.ctx.terminal().mode().intersects(mouse_mode) || modifiers.shift) && self.mouse_config.url.launcher.is_some() { - let url_bounds = self.url_bounds_at_point(url, point); + let url_bounds = url.linear_bounds(self.ctx.terminal()); self.ctx.terminal_mut().set_url_highlight(url_bounds); self.ctx.terminal_mut().set_mouse_cursor(MouseCursor::Hand); self.ctx.terminal_mut().dirty = true; @@ -485,47 +486,6 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { } } - fn url_bounds_at_point(&self, url: Url, point: Point) -> RangeInclusive<Linear> { - let Url { origin, text } = url; - let cols = self.ctx.size_info().cols().0; - - // Calculate the URL's start position - let lines_before = (origin + cols - point.col.0 - 1) / cols; - let (start_col, start_line) = if lines_before > point.line.0 { - (0, 0) - } else { - let start_col = (cols + point.col.0 - origin % cols) % cols; - let start_line = point.line.0 - lines_before; - (start_col, start_line) - }; - - let start = Point::new(start_line, Column(start_col)); - - // Calculate the URL's highlight end position - let len = text.width(); - let url_end_col_denormilized = point.col.0 + len - origin; - - // This means that url ends at the last cell of the line - let end_col = if url_end_col_denormilized % cols == 0 { - cols - 1 - } else { - url_end_col_denormilized % cols - 1 - }; - - let end_line = if end_col == cols - 1 { - point.line.0 + (url_end_col_denormilized) / cols - 1 - } else { - point.line.0 + (url_end_col_denormilized) / cols - }; - - let end = Point::new(end_line, Column(end_col)); - - let start = Linear::from_point(Column(cols), start); - let end = Linear::from_point(Column(cols), end); - - RangeInclusive::new(start, end) - } - fn get_mouse_side(&self) -> Side { let size_info = self.ctx.size_info(); let x = self.ctx.mouse().x; @@ -705,7 +665,9 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { return None; } - let text = self.ctx.terminal().url_search(point.into())?.text; + 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(); |