aboutsummaryrefslogtreecommitdiff
path: root/src/term/mod.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-03-24 17:37:30 +0000
committerGitHub <noreply@github.com>2019-03-24 17:37:30 +0000
commit3e36d714fec8139a1e506036a394b343bd1a8bb4 (patch)
tree88cd59c895bfec86b787fac84f93713683fb502a /src/term/mod.rs
parentd8272662db4a4dc1ef58b8379dc88162066a3241 (diff)
downloadalacritty-3e36d714fec8139a1e506036a394b343bd1a8bb4.tar.gz
alacritty-3e36d714fec8139a1e506036a394b343bd1a8bb4.zip
Fix URL highlight crash
The URL highlight stores the state of the last URL highlight with the position of the URL start position. However when resizing, it's possible that the indices of this point change which will cause a crash if the old positions are not within the grid anymore. This has been resolved by resetting the URL highlight state whenever the terminal is resized. The original PR incorrectly required the shift modifier to be required when the user was in the alternate screen buffer. However the correct behavior is to require it when the mouse mode is enabled. This has been resolved and URLs are now highlighted in the alt screen even if no shift modifier is pressed. This fixes #2194.
Diffstat (limited to 'src/term/mod.rs')
-rw-r--r--src/term/mod.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs
index ac5a9a5f..fc2b1727 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -17,6 +17,7 @@ use std::ops::{Range, Index, IndexMut, RangeInclusive};
use std::{ptr, io, mem};
use std::cmp::{min, max};
use std::time::{Duration, Instant};
+use std::iter::once;
use arraydeque::ArrayDeque;
use unicode_width::UnicodeWidthChar;
@@ -36,7 +37,7 @@ use crate::input::FONT_SIZE_STEP;
use crate::url::{Url, UrlParser};
use crate::message_bar::MessageBuffer;
use crate::term::color::Rgb;
-use crate::term::cell::{LineLength, Cell};
+use crate::term::cell::{LineLength, Cell, Flags};
#[cfg(windows)]
use crate::tty;
@@ -823,6 +824,16 @@ pub struct Term {
/// Hint that Alacritty should be closed
should_exit: bool,
+
+ /// URL highlight save state
+ url_hover_save: Option<UrlHoverSaveState>,
+}
+
+/// 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>,
}
/// Terminal size info
@@ -955,6 +966,7 @@ impl Term {
auto_scroll: config.scrolling().auto_scroll,
message_buffer,
should_exit: false,
+ url_hover_save: None,
}
}
@@ -1200,6 +1212,8 @@ impl Term {
return;
}
+ self.reset_url_highlight();
+
let old_cols = self.grid.num_cols();
let old_lines = self.grid.num_lines();
let mut num_cols = size.cols();
@@ -1365,6 +1379,41 @@ impl Term {
pub fn should_exit(&self) -> bool {
self.should_exit
}
+
+ #[inline]
+ pub fn set_url_highlight(&mut self, hover_save: UrlHoverSaveState) {
+ self.url_hover_save = Some(hover_save);
+ }
+
+ #[inline]
+ pub fn url_highlight_start(&self) -> Option<Point<usize>> {
+ self.url_hover_save.as_ref().map(|hs| hs.start)
+ }
+
+ /// Remove the URL highlight and restore the previous mouse cursor and underline state.
+ pub fn reset_url_highlight(&mut self) {
+ let hover_save = match self.url_hover_save.take() {
+ Some(hover_save) => hover_save,
+ _ => return,
+ };
+
+ // Reset the mouse cursor
+ self.set_mouse_cursor(hover_save.mouse_cursor);
+
+ let last_line = self.size_info.lines().0 - 1;
+ let last_col = self.size_info.cols() - 1;
+
+ // Reset the underline state after unhovering a URL
+ let mut iter = once(hover_save.start).chain(hover_save.start.iter(last_col, last_line));
+ for underlined in &hover_save.underlined {
+ if let (Some(point), false) = (iter.next(), underlined) {
+ let cell = &mut self.grid[point.line][point.col];
+ cell.flags.remove(Flags::UNDERLINE);
+ }
+ }
+
+ self.dirty = true;
+ }
}
impl ansi::TermInfo for Term {