Preserve composer hyperlinks across wrapped lines (#40720)

## What changed

- Detect visible HTTP(S) URLs in the composer and attach the complete OSC 8 destination to every wrapped fragment, including when part of the URL is scrolled offscreen.
- Cache hyperlink metadata with the textarea wrap state while leaving masked input and destinations larger than 8 KiB unannotated.
- Make shared hyperlink mapping grapheme-aware, recognize Unicode whitespace boundaries, and scan URLs and trailing delimiters incrementally for large inputs.

## Testing

- Add coverage for wrapped and scrolled URLs, joined emoji, Unicode whitespace, preserved highlighting, masked input, cache invalidation, oversized destinations, and drafts containing many URLs.

GitOrigin-RevId: 40facdf2fe79438c91c82bff2d849c342f1ab28a
This commit is contained in:
Charlie Marsh authored and copyberry committed 2026-08-25 22:05:48 +00:00
1 parent 42624fd63b
commit d6174a8798
9 files changed
+726 -50

No files matched your search

+17 -2
View File
@@ -13,6 +13,8 @@
//! Wrapping also reserves a visible insertion point: full logical lines get continuation rows,
//! and trailing spaces wrap instead of moving the cursor outside the textarea. At soft word
//! breaks, interior separators hang off the preceding row without changing the editable text.
//! Visible web URLs carry their complete terminal hyperlink destination across wrapped rows;
//! masked rendering never exposes hyperlink destinations.
use crate::key_hint::KeyBindingListExt;
use crate::key_hint::is_altgr;
@@ -38,12 +40,14 @@ use ratatui::text::Span;
use ratatui::widgets::StatefulWidgetRef;
use ratatui::widgets::WidgetRef;
use std::borrow::Cow;
use std::cell::OnceCell;
use std::cell::Ref;
use std::cell::RefCell;
use std::ops::Range;
use std::sync::Arc;
use unicode_segmentation::UnicodeSegmentation;
mod hyperlinks;
mod vim;
mod vim_commands;
mod wrapping;
@@ -147,6 +151,7 @@ pub(crate) struct TextArea {
struct WrapCache {
width: u16,
lines: Vec<Range<usize>>,
hyperlinks: OnceCell<hyperlinks::HyperlinkCache>,
}
#[derive(Debug, Default, Clone, Copy)]
@@ -1994,7 +1999,11 @@ impl TextArea {
if needs_recalc {
let display_text = text_for_display(&self.text);
let lines = wrapping::wrapped_lines(display_text.as_ref(), width);
*cache = Some(WrapCache { width, lines });
*cache = Some(WrapCache {
width,
lines,
hyperlinks: OnceCell::new(),
});
}
}
@@ -2107,7 +2116,7 @@ impl TextArea {
highlights: &[(Range<usize>, Style)],
) {
let element_style = base_style.fg(Color::Cyan);
for (row, idx) in range.enumerate() {
for (row, idx) in range.clone().enumerate() {
let r = &lines[idx];
let y = area.y + row as u16;
let visible = wrapping::visible_prefix(&self.text[r.start..r.end - 1], area.width);
@@ -2149,6 +2158,12 @@ impl TextArea {
);
}
}
if let Some(wrap_cache) = self.wrap_cache.borrow().as_ref() {
wrap_cache
.hyperlinks
.get_or_init(|| hyperlinks::HyperlinkCache::new(&self.text, lines))
.mark(buf, area, &self.text, lines, range);
}
}
/// Renders width-preserving mask glyphs without writing outside the textarea viewport.