mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Avoid cloning hyperlink text during TUI rendering (#34366)
## What changed Add a borrowed `Line` conversion and use it when rendering and measuring hyperlink-aware history and pager content. This preserves line styling and alignment while avoiding clones of the underlying span strings. GitOrigin-RevId: c9cd6ff5ec63cd29719ea2ae51acede7364f2bd8
This commit is contained in:
1 parent
f944456d81
commit
28aacbb9d9
4 files changed
+32
-6
No files matched your search
@@ -19,6 +19,7 @@ use unicode_width::UnicodeWidthChar;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use url::Url;
|
||||
|
||||
use crate::render::line_utils::line_to_borrowed;
|
||||
use crate::render::line_utils::line_to_static;
|
||||
use crate::wrapping::RtOptions;
|
||||
use crate::wrapping::adaptive_wrap_line;
|
||||
@@ -127,6 +128,13 @@ pub(crate) fn visible_lines(lines: Vec<HyperlinkLine>) -> Vec<Line<'static>> {
|
||||
lines.into_iter().map(|line| line.line).collect()
|
||||
}
|
||||
|
||||
pub(crate) fn visible_lines_ref(lines: &[HyperlinkLine]) -> Vec<Line<'_>> {
|
||||
lines
|
||||
.iter()
|
||||
.map(|line| line_to_borrowed(&line.line))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn plain_hyperlink_lines(lines: Vec<Line<'static>>) -> Vec<HyperlinkLine> {
|
||||
lines.into_iter().map(HyperlinkLine::new).collect()
|
||||
}
|
||||
@@ -483,7 +491,8 @@ pub(crate) fn mark_buffer_hyperlinks(
|
||||
}
|
||||
let mut logical_row = 0usize;
|
||||
for line in lines {
|
||||
let paragraph = Paragraph::new(Text::from(line.line.clone())).wrap(Wrap { trim: false });
|
||||
let paragraph =
|
||||
Paragraph::new(Text::from(line_to_borrowed(&line.line))).wrap(Wrap { trim: false });
|
||||
let rendered_height = paragraph.line_count(area.width).max(/*other*/ 1);
|
||||
if line.hyperlinks.is_empty() {
|
||||
logical_row += rendered_height;
|
||||
|
||||
Reference in new issue
Block a user