mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Select and copy Markdown blocks in the transcript (#63047)
## What changed Press `m` in transcript selection mode to mark the Markdown block at the cursor. Move between sibling blocks with `h` and `l`, or extend the selection with `j` and `k`. Use `Tab` to expand to an enclosing block or heading section and `Shift+Tab` to shrink the selection. Copy with `y` to retain Markdown structure, including list markers, code fence languages, and table formatting. For example, you can copy a fenced code block on its own from inside a blockquote. ## Testing Add coverage for wrapped blocks, nested lists and sections, table selection, copying from the displayed revision during streaming, and conflicts with customized keybindings. GitOrigin-RevId: 5d4d873c0e378294128c128f472e4dae122831c6
This commit is contained in:
@@ -168,6 +168,19 @@ impl Selection {
|
||||
self.preferred_column = None;
|
||||
}
|
||||
|
||||
pub(super) fn set_keyboard_block_range(
|
||||
&mut self,
|
||||
start: Anchor,
|
||||
end: Anchor,
|
||||
layout: Arc<TextLayout>,
|
||||
) {
|
||||
self.snapshot.pinned.entry(start.key).or_insert(layout);
|
||||
self.set_keyboard_range(start, end);
|
||||
// A parent and child can have identical bounds but different clipboard syntax.
|
||||
self.primary_owner = None;
|
||||
self.pending_copy = None;
|
||||
}
|
||||
|
||||
pub(super) fn set_keyboard_table_range(
|
||||
&mut self,
|
||||
entry: Anchor,
|
||||
@@ -465,7 +478,7 @@ impl TranscriptView {
|
||||
&mut self,
|
||||
cells: &[Arc<dyn HistoryCell>],
|
||||
) -> Option<Vec<(Arc<TextLayout>, std::ops::Range<usize>)>> {
|
||||
if !self.has_selection_range() {
|
||||
if !self.has_selection_range() && self.marked_block().is_none() {
|
||||
return None;
|
||||
}
|
||||
let snapshot = self.snapshot_cells();
|
||||
@@ -504,6 +517,12 @@ impl TranscriptView {
|
||||
}
|
||||
|
||||
pub(crate) fn selected_text(&mut self, cells: &[Arc<dyn HistoryCell>]) -> Option<String> {
|
||||
if let Some(block) = self.marked_block() {
|
||||
let outer_prefix = block.outer_prefix;
|
||||
let lines = self.selected_copy_lines(cells);
|
||||
let text = crate::markdown_copy::block_selection(&lines, outer_prefix);
|
||||
return (!text.is_empty()).then_some(text);
|
||||
}
|
||||
if let Some(table) = self.table_selection() {
|
||||
let rectangle_rows = table.rectangle_rows();
|
||||
let lines = self.selected_copy_lines(cells);
|
||||
@@ -577,10 +596,6 @@ impl TranscriptView {
|
||||
crate::clipboard_copy::CopyFormat,
|
||||
) -> Result<crate::clipboard_copy::CopyStatus, String>,
|
||||
) -> Result<crate::clipboard_copy::CopyStatus, String> {
|
||||
let lines = self.selected_copy_lines(cells);
|
||||
let rectangle_rows = self
|
||||
.table_selection()
|
||||
.and_then(TableSelection::rectangle_rows);
|
||||
let override_payload = self.copy_mode.as_ref().and_then(|mode| {
|
||||
if mode.whole {
|
||||
mode.response.as_ref().map(|(_, text)| {
|
||||
@@ -596,6 +611,13 @@ impl TranscriptView {
|
||||
}
|
||||
});
|
||||
let (text, format) = override_payload.unwrap_or_else(|| {
|
||||
if self.marked_block().is_some() {
|
||||
return (text.to_owned(), CopyFormat::Markdown);
|
||||
}
|
||||
let lines = self.selected_copy_lines(cells);
|
||||
let rectangle_rows = self
|
||||
.table_selection()
|
||||
.and_then(TableSelection::rectangle_rows);
|
||||
let (serialized, format) =
|
||||
crate::markdown_copy::selection(&lines, text, rectangle_rows.as_ref());
|
||||
if format == CopyFormat::Markdown {
|
||||
@@ -881,6 +903,7 @@ impl TranscriptView {
|
||||
} else {
|
||||
(selection.end, selection.start)
|
||||
};
|
||||
let marked_block = self.marked_block().is_some();
|
||||
for (y, visible) in self.visible.iter().enumerate() {
|
||||
if visible.index < start.index || visible.index > end.index {
|
||||
continue;
|
||||
@@ -901,9 +924,10 @@ impl TranscriptView {
|
||||
self.area.width,
|
||||
/*height*/ 1,
|
||||
);
|
||||
if self.copy_mode.is_some() {
|
||||
// Full-entry selections include final padding; partial ranges stay half-open.
|
||||
let last = if begin == 0 && finish == visible.layout.text().len() {
|
||||
if self.copy_mode.is_some() || marked_block {
|
||||
// Block ranges end on the final logical line, even when it is marker-only.
|
||||
let last = if marked_block || (begin == 0 && finish == visible.layout.text().len())
|
||||
{
|
||||
finish
|
||||
} else {
|
||||
finish.saturating_sub(/*rhs*/ 1)
|
||||
|
||||
Reference in New Issue
Block a user