fix-deviant(links): bound hover lookup and renderer regex work

Follow-up testing showed that the mailbox limit did not fix the base64
hang: moving the pointer stalled the app, and opening a tab could hang it.
Mouse link lookup copied the entire wrapped line before checking modifier
eligibility, while renderer link searches had no whole-search work budget.

Filter eligible links before traversing scrollback. Add bounded logical
line selection and skip automatic regex lookup on lines exceeding 65,536
grid cells. Keep explicit line selection and OSC8 handling unrestricted.
Skip oversized lines instead of truncating URLs into different targets.

Apply the existing terminal StringMap retry budget to renderer searches
and handle search errors without panicking. The regression triggered a
retry-limit panic through the old onig search API and now returns normally,
allowing subsequent link patterns to run.

Document the lookup limits and correct the earlier mailbox fix entry to
record that it did not resolve the reported hang on its own.

Test Plan:
- 1,513 unit/integration tests and one doctest pass across core, renderer,
  and terminal with Mesa software OpenGL; one existing doctest is ignored.
- Release application build, formatting, and all-target Clippy pass.
- GTK handles 400 pointer moves, including Ctrl hover, during continuous
  base64 output, opens/closes a tab, handles Ctrl+C, prints a marker, and
  exits cleanly. Normal URL hover still works after a hard newline.

Reference: docs/rewrite/DEVIANT_FIXES.md (entry 41)
This commit is contained in:
ddidderr committed 2026-10-15 00:02:47 +02:00
1 parent 4c31d27888
commit 9010117d08
9 files changed
+153 -24

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ ghostty-os.workspace = true
ghostty-datastruct.workspace = true
ghostty-font.workspace = true
ghostty-input.workspace = true
ghostty-onig.workspace = true
ghostty-terminal.workspace = true
ghostty-unicode.workspace = true
ghostty-vt.workspace = true
+32 -3
View File
@@ -7,7 +7,12 @@ use ghostty_input::{
link::{Highlight, Link as InputLink},
};
use ghostty_terminal::{point::Coordinate, render::RenderState};
use onig::{Regex, Region, SearchOptions};
use onig::{MatchParam, Regex, Region, SearchOptions};
/// Match the whole-search work budget used by terminal StringMap searches.
/// Renderer searches also need a limit: a busy matcher holds the renderer
/// thread's state lock and can block tab switches and renderer shutdown.
const ONI_SEARCH_RETRY_LIMIT: u32 = 100_000;
#[derive(Debug, thiserror::Error)]
pub enum Error {
@@ -103,16 +108,20 @@ impl Set {
while offset < str.len() {
let haystack = &str[offset..];
let mut region = Region::new();
let found = link.regex.search_with_options(
let mut param = MatchParam::default();
ghostty_onig::set_retry_limit_in_search(&mut param, ONI_SEARCH_RETRY_LIMIT);
let found = link.regex.search_with_param(
haystack,
0,
haystack.len(),
SearchOptions::SEARCH_OPTION_NONE,
Some(&mut region),
param,
);
// A mismatch (or any search failure such as hitting the
// retry limit) ends the search for this link.
let Some((offset_start, offset_end)) = found.and(region.pos(0)) else {
let Some((offset_start, offset_end)) = found.ok().flatten().and(region.pos(0))
else {
break;
};
@@ -284,4 +293,24 @@ mod tests {
fn invalid_regex_is_error() {
assert!(Set::from_config(&[link("(", Highlight::Always)]).is_err());
}
#[test]
fn render_cell_map_limits_backtracking_and_continues_with_other_links() {
let mut t = Terminal::new(Options::new(80, 1)).unwrap();
// A long near-match must not monopolize the renderer thread. In a
// tab switch the main thread may need that thread's locks to proceed.
let text = format!("{}b", "a".repeat(60));
t.vt_stream().next_slice(text.as_bytes()).unwrap();
let mut state = RenderState::new();
state.update(&mut t).unwrap();
let set = Set::from_config(&[
link("(a+)+$", Highlight::Always),
link("b", Highlight::Always),
])
.unwrap();
let mut result = HashSet::new();
set.render_cell_map(&mut result, &state, None, Mods::default())
.unwrap();
assert_eq!(result, HashSet::from([c(60, 0)]));
}
}