aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/grid/mod.rs36
-rw-r--r--alacritty_terminal/src/input.rs45
-rw-r--r--alacritty_terminal/src/term/mod.rs1
-rw-r--r--alacritty_terminal/src/url.rs3
4 files changed, 37 insertions, 48 deletions
diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs
index e2cda175..2d191d20 100644
--- a/alacritty_terminal/src/grid/mod.rs
+++ b/alacritty_terminal/src/grid/mod.rs
@@ -119,13 +119,6 @@ pub enum Scroll {
Bottom,
}
-#[derive(Copy, Clone)]
-enum ViewportPosition {
- Visible(Line),
- Above,
- Below,
-}
-
impl<T: GridCell + Copy + Clone> Grid<T> {
pub fn new(lines: index::Line, cols: index::Column, scrollback: usize, template: T) -> Grid<T> {
let raw = Storage::with_capacity(lines, Row::new(cols, &template));
@@ -144,30 +137,19 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
pub fn buffer_to_visible(&self, point: impl Into<Point<usize>>) -> Point<usize> {
let mut point = point.into();
- match self.buffer_line_to_visible(point.line) {
- ViewportPosition::Visible(line) => point.line = line.0,
- ViewportPosition::Above => {
- point.col = Column(0);
- point.line = 0;
- },
- ViewportPosition::Below => {
- point.col = self.num_cols();
- point.line = self.num_lines().0 - 1;
- },
- }
+ let offset = point.line.saturating_sub(self.display_offset);
- point
- }
-
- fn buffer_line_to_visible(&self, line: usize) -> ViewportPosition {
- let offset = line.saturating_sub(self.display_offset);
- if line < self.display_offset {
- ViewportPosition::Below
+ if point.line < self.display_offset {
+ point.col = self.num_cols();
+ point.line = self.num_lines().0 - 1;
} else if offset >= *self.num_lines() {
- ViewportPosition::Above
+ point.col = Column(0);
+ point.line = 0;
} else {
- ViewportPosition::Visible(self.lines - offset - 1)
+ point.line = self.lines.0 - offset - 1;
}
+
+ point
}
pub fn visible_to_buffer(&self, point: Point) -> Point<usize> {
diff --git a/alacritty_terminal/src/input.rs b/alacritty_terminal/src/input.rs
index 8eceef16..3cf6247c 100644
--- a/alacritty_terminal/src/input.rs
+++ b/alacritty_terminal/src/input.rs
@@ -389,23 +389,34 @@ enum MousePosition {
}
impl<'a, A: ActionContext + 'a> Processor<'a, A> {
- fn mouse_position(&mut self, point: Point) -> MousePosition {
+ fn mouse_position(&mut self, point: Point, modifiers: ModifiersState) -> MousePosition {
+ let mouse_mode =
+ TermMode::MOUSE_MOTION | TermMode::MOUSE_DRAG | TermMode::MOUSE_REPORT_CLICK;
+
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
+ return MousePosition::MessageBarButton;
} else {
- MousePosition::MessageBar
+ return MousePosition::MessageBar;
}
- } else if let Some(url) =
- self.ctx.terminal().urls().drain(..).find(|url| url.contains(buffer_point))
+ }
+
+ // Check for URL at point with required modifiers held
+ if self.mouse_config.url.mods().relaxed_eq(modifiers)
+ && (!self.ctx.terminal().mode().intersects(mouse_mode) || modifiers.shift)
+ && self.mouse_config.url.launcher.is_some()
{
- MousePosition::Url(url)
- } else {
- MousePosition::Terminal
+ if let Some(url) =
+ self.ctx.terminal().urls().drain(..).find(|url| url.contains(buffer_point))
+ {
+ return MousePosition::Url(url);
+ }
}
+
+ MousePosition::Terminal
}
#[inline]
@@ -435,20 +446,12 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
// Don't launch URLs if mouse has moved
self.ctx.mouse_mut().block_url_launcher = true;
- match self.mouse_position(point) {
+ match self.mouse_position(point, modifiers) {
MousePosition::Url(url) => {
- let mouse_mode =
- TermMode::MOUSE_MOTION | TermMode::MOUSE_DRAG | TermMode::MOUSE_REPORT_CLICK;
-
- if self.mouse_config.url.mods().relaxed_eq(modifiers)
- && (!self.ctx.terminal().mode().intersects(mouse_mode) || modifiers.shift)
- && self.mouse_config.url.launcher.is_some()
- {
- 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;
- }
+ 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;
},
MousePosition::MessageBar => {
self.ctx.terminal_mut().reset_url_highlight();
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 0cc2cd6d..2d1ec392 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -1350,6 +1350,7 @@ impl Term {
parser.reset();
}
+ // Advance parser
match parser.advance(cell.c) {
ParserState::Url(length) => {
urls.push(Url::new(point, length + extra_url_len, num_cols))
diff --git a/alacritty_terminal/src/url.rs b/alacritty_terminal/src/url.rs
index f1b7934b..292f8358 100644
--- a/alacritty_terminal/src/url.rs
+++ b/alacritty_terminal/src/url.rs
@@ -18,14 +18,17 @@ impl Url {
Url { end: Point::new(end_line, Column(end_col)), start }
}
+ /// Check if point is within this URL
pub fn contains(&self, point: impl Into<Point<usize>>) -> bool {
let point = point.into();
+
point.line <= self.start.line
&& point.line >= self.end.line
&& (point.line != self.start.line || point.col >= self.start.col)
&& (point.line != self.end.line || point.col <= self.end.col)
}
+ /// Convert URLs bounding points to linear indices
pub fn linear_bounds(&self, terminal: &Term) -> RangeInclusive<Linear> {
let mut start = self.start;
let mut end = self.end;