mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Speed up TUI Markdown layout (#34216)
## What changed - Allocate Markdown table widths in bulk while preserving the existing column shrink priorities and balancing behavior. - Reuse flattened styled-line data during adaptive wrapping and detect URLs across span boundaries. - Remap wrapped terminal hyperlinks with a single forward scan. ## Testing - Verify bulk table shrinking matches the previous one-cell-at-a-time results, including a token-heavy column with a million-character width. - Cover URLs split across styled spans and multiple links on indented Unicode lines. GitOrigin-RevId: 24a6fd6fdace6ca948e613d67c130a3a7f8d1a4e
This commit is contained in:
1 parent
3e2f79727a
commit
aa982319c2
3 files changed
+298
-110
No files matched your search
@@ -207,9 +207,14 @@ pub(crate) fn remap_wrapped_line(
|
||||
wrapped: Vec<Line<'static>>,
|
||||
) -> Vec<HyperlinkLine> {
|
||||
let mut out = plain_hyperlink_lines(wrapped);
|
||||
if source.hyperlinks.is_empty() {
|
||||
return out;
|
||||
}
|
||||
|
||||
let source_text = line_text(&source.line);
|
||||
let mut source_byte = 0usize;
|
||||
let mut source_column = 0usize;
|
||||
let mut link_index = 0usize;
|
||||
for (index, line) in out.iter_mut().enumerate() {
|
||||
if index > 0 {
|
||||
let trimmed = source_text[source_byte..].trim_start_matches(char::is_whitespace);
|
||||
@@ -227,10 +232,17 @@ pub(crate) fn remap_wrapped_line(
|
||||
let mut output_column = rendered[..rendered_start].width();
|
||||
for ch in mapped.chars() {
|
||||
let width = ch.width().unwrap_or(/*default*/ 0);
|
||||
while source
|
||||
.hyperlinks
|
||||
.get(link_index)
|
||||
.is_some_and(|link| link.columns.end <= source_column)
|
||||
{
|
||||
link_index += 1;
|
||||
}
|
||||
if let Some(link) = source
|
||||
.hyperlinks
|
||||
.iter()
|
||||
.find(|link| link.columns.contains(&source_column))
|
||||
.get(link_index)
|
||||
.filter(|link| link.columns.contains(&source_column))
|
||||
{
|
||||
push_link_range(line, output_column..output_column + width, link);
|
||||
}
|
||||
@@ -636,6 +648,50 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapping_maps_multiple_links_across_indented_unicode_lines() {
|
||||
let text = "alpha 😀here middle there end";
|
||||
let first_start = text.find("here").expect("first link");
|
||||
let second_start = text.find("there").expect("second link");
|
||||
let mut source = HyperlinkLine::new(Line::from(text));
|
||||
source.hyperlinks.push(TerminalHyperlink::web(
|
||||
text[..first_start].width()..text[..first_start].width() + "here".width(),
|
||||
"https://example.com/first".to_string(),
|
||||
));
|
||||
source.hyperlinks.push(TerminalHyperlink::web(
|
||||
text[..second_start].width()..text[..second_start].width() + "there".width(),
|
||||
"https://example.com/second".to_string(),
|
||||
));
|
||||
|
||||
let wrapped = remap_wrapped_line(
|
||||
&source,
|
||||
vec![
|
||||
Line::from(" alpha 😀here"),
|
||||
Line::from(" middle there end"),
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
wrapped,
|
||||
vec![
|
||||
HyperlinkLine {
|
||||
line: Line::from(" alpha 😀here"),
|
||||
hyperlinks: vec![TerminalHyperlink::web(
|
||||
/*columns*/ 10..14,
|
||||
"https://example.com/first".to_string(),
|
||||
)],
|
||||
},
|
||||
HyperlinkLine {
|
||||
line: Line::from(" middle there end"),
|
||||
hyperlinks: vec![TerminalHyperlink::web(
|
||||
/*columns*/ 11..16,
|
||||
"https://example.com/second".to_string(),
|
||||
)],
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffer_hyperlinks_follow_word_wrapping() {
|
||||
let destination = "https://example.com/path";
|
||||
|
||||
Reference in new issue
Block a user