mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Allow selecting and copying TUI turn tips (#53152)
## Why Turn tips are visible outside transcript history, but their text could not be selected for copying. ## What changed Register rendered working and completion tip rows for mouse selection. Keep tips in place when selection hints or copy status appear, and use the hint “Selecting text · esc cancel”. ## Testing Extend mouse-selection tests and snapshots to cover selecting `/help` in working and completion tips with copy-on-select enabled, and clearing the selection when a working tip disappears. GitOrigin-RevId: 25b3f02e7e93a53e777de455943d47fbab388ff1
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! Compose the owned transcript above the composer and route their selection gestures.
|
||||
//! Reserve a cleared row below activity and previews, immediately above the composer.
|
||||
//! Slash suggestions overlay already-painted rows so opening or closing them leaves transcript
|
||||
//! geometry unchanged. Turn tips remain separate from selectable transcript text.
|
||||
//! geometry unchanged. Turn tips remain outside transcript history; their painted rows are selectable.
|
||||
//! Plain Enter returns an empty composer to latest after transcript interactions and prompt editing.
|
||||
|
||||
use super::turn_tips::TipSurface;
|
||||
@@ -97,7 +97,7 @@ impl App {
|
||||
.has_active_interaction()
|
||||
{
|
||||
Some(
|
||||
ratatui::text::Line::from("Selecting footer · esc cancel")
|
||||
ratatui::text::Line::from("Selecting text · esc cancel")
|
||||
.dim()
|
||||
.into(),
|
||||
)
|
||||
@@ -194,6 +194,8 @@ impl App {
|
||||
);
|
||||
if let Some(gap) = composer_gap.as_mut() {
|
||||
gap.needs_separator = available > 1
|
||||
// Keep the tip under the pointer when selection hints or copy feedback appear.
|
||||
&& turn_tip.is_none()
|
||||
&& chat_widget.no_modal_or_popup_active()
|
||||
&& view.composer_gap_has_content(transcript_width, composer_hint.as_ref(), now);
|
||||
}
|
||||
@@ -287,6 +289,14 @@ impl App {
|
||||
.filter(|_| chat_widget.no_modal_or_popup_active());
|
||||
feedback_tick =
|
||||
view.render_composer_gap(follow_area, composer_hint.as_ref(), frame.buffer, now);
|
||||
if let Some((_, tip)) = &turn_tip
|
||||
&& let Some(area) = tip.rendered.get()
|
||||
{
|
||||
chat_widget
|
||||
.rendered_selection
|
||||
.borrow_mut()
|
||||
.register(area, /*invalidate*/ false);
|
||||
}
|
||||
chat_widget
|
||||
.rendered_selection
|
||||
.borrow_mut()
|
||||
@@ -313,7 +323,7 @@ impl App {
|
||||
}
|
||||
})?;
|
||||
if let Some((surface, tip)) = &turn_tip
|
||||
&& tip.rendered.get()
|
||||
&& tip.rendered.get().is_some()
|
||||
{
|
||||
self.turn_tips.acknowledge(*surface);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
---
|
||||
source: tui/src/app/owned_transcript_tests.rs
|
||||
assertion_line: 1545
|
||||
assertion_line: 1831
|
||||
expression: "normalize_snapshot_paths(buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal)))"
|
||||
---
|
||||
|
||||
@@ -21,7 +21,7 @@ expression: "normalize_snapshot_paths(buffer_text(crate::custom_terminal::test_s
|
||||
|
||||
|
||||
|
||||
Selecting footer · esc cancel
|
||||
Selecting text · esc cancel
|
||||
|
||||
› draft stays here
|
||||
|
||||
|
||||
+53
@@ -1,5 +1,6 @@
|
||||
---
|
||||
source: tui/src/app/turn_tips_tests.rs
|
||||
assertion_line: 387
|
||||
expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(screens.join(\"\\n\\n\"))"
|
||||
---
|
||||
working=true, response rows=1, 80x12
|
||||
@@ -33,6 +34,58 @@ working=false, response rows=1, 80x12
|
||||
Worked for [duration] • [completion time]
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-test default · /tmp/project
|
||||
? for shortcuts
|
||||
|
||||
working=false, response rows=1, 80x24
|
||||
|
||||
› Show a response.
|
||||
|
||||
|
||||
Response row 0
|
||||
|
||||
• Done.
|
||||
└ Tip: Try /help.
|
||||
|
||||
Worked for [duration] • [completion time]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-test default · /tmp/project
|
||||
? for shortcuts
|
||||
|
||||
Completion tip selected, 80x24
|
||||
|
||||
› Show a response.
|
||||
|
||||
|
||||
Response row 0
|
||||
|
||||
• Done.
|
||||
└ Tip: Try /help.
|
||||
|
||||
Worked for [duration] • [completion time]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Copying 5 chars…
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-test default · /tmp/project
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
---
|
||||
source: tui/src/app/turn_tips_tests.rs
|
||||
assertion_line: 485
|
||||
expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal),))"
|
||||
---
|
||||
Response row 0
|
||||
Response row 1
|
||||
Response row 2
|
||||
Response row 3
|
||||
Response row 4
|
||||
Response row 5
|
||||
Response row 6
|
||||
Response row 7
|
||||
Response row 8
|
||||
Response row 9
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
• Working (0s • esc to interrupt)
|
||||
└ Tip: Try /help.
|
||||
Copying 5 chars…
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-test default · /tmp/project
|
||||
? for shortcuts
|
||||
@@ -190,6 +190,7 @@ async fn turn_tip_placements_and_completion_barrier() -> Result<()> {
|
||||
(true, 1, 80, 12),
|
||||
(true, 1, 80, 6),
|
||||
(false, 1, 80, 12),
|
||||
(false, 1, 80, 24),
|
||||
(false, 30, 80, 12),
|
||||
(false, 1, 80, 9),
|
||||
(false, 1, 80, 10),
|
||||
@@ -281,6 +282,44 @@ async fn turn_tip_placements_and_completion_barrier() -> Result<()> {
|
||||
assert_eq!(app.turn_tips.completions_shown, usize::from(!working));
|
||||
}
|
||||
if !working && shown {
|
||||
if rows == 1 && size == tui.terminal.size()? {
|
||||
app.local_settings.tui.copy_on_select = CopyOnSelect::Always;
|
||||
let (row, line) = screen
|
||||
.lines()
|
||||
.enumerate()
|
||||
.find(|(_, line)| line.contains("└ Tip:"))
|
||||
.unwrap();
|
||||
let column = line[..line.find("/help").unwrap()].chars().count() as u16;
|
||||
for (kind, column) in [
|
||||
(Down(Left), column),
|
||||
(Drag(Left), column + 5),
|
||||
(Up(Left), column + 5),
|
||||
] {
|
||||
assert!(app.handle_rendered_selection_event(
|
||||
&mut tui,
|
||||
&TuiEvent::Mouse(MouseEvent {
|
||||
kind,
|
||||
column,
|
||||
row: row as u16,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
}),
|
||||
)?);
|
||||
app.render_owned_transcript(&mut tui, size)?;
|
||||
}
|
||||
let mut selection = app.chat_widget.rendered_selection.borrow_mut();
|
||||
let crate::rendered_selection::RenderedSelection { view, cells, .. } =
|
||||
&mut *selection;
|
||||
assert_eq!(view.selected_text(cells), Some("/help".into()));
|
||||
screens.push(format!(
|
||||
"Completion tip selected, {width}x{height}\n{}",
|
||||
crate::chatwidget::tests::helpers::normalize_completion_timestamps(
|
||||
app.transcript_cells.last().unwrap().as_ref(),
|
||||
buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(
|
||||
&tui.terminal,
|
||||
)),
|
||||
)
|
||||
));
|
||||
}
|
||||
assert!(
|
||||
!app.transcript_cells
|
||||
.iter()
|
||||
@@ -448,6 +487,46 @@ async fn working_tip_stays_put_through_mouse_selection() -> Result<()> {
|
||||
app.transcript_view.selected_text(&app.transcript_cells),
|
||||
Some("ponse".into()),
|
||||
);
|
||||
// Start from the usual following viewport, without an existing transcript selection.
|
||||
app.transcript_view.jump_to_latest();
|
||||
app.local_settings.tui.copy_on_select = CopyOnSelect::Always;
|
||||
app.render_owned_transcript(&mut tui, size)?;
|
||||
let before = buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(
|
||||
&tui.terminal,
|
||||
));
|
||||
let (tip_row, tip_line) = before
|
||||
.lines()
|
||||
.enumerate()
|
||||
.find(|(_, line)| line.contains("└ Tip:"))
|
||||
.unwrap();
|
||||
let column = tip_line[..tip_line.find("/help").unwrap()].chars().count() as u16;
|
||||
for (kind, column) in [
|
||||
(Down(Left), column),
|
||||
(Drag(Left), column + 5),
|
||||
(Up(Left), column + 5),
|
||||
] {
|
||||
assert!(app.handle_rendered_selection_event(
|
||||
&mut tui,
|
||||
&TuiEvent::Mouse(MouseEvent {
|
||||
kind,
|
||||
column,
|
||||
row: tip_row as u16,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
}),
|
||||
)?);
|
||||
app.render_owned_transcript(&mut tui, size)?;
|
||||
}
|
||||
{
|
||||
let mut selection = app.chat_widget.rendered_selection.borrow_mut();
|
||||
let crate::rendered_selection::RenderedSelection { view, cells, .. } = &mut *selection;
|
||||
assert_eq!(view.selected_text(cells), Some("/help".into()));
|
||||
}
|
||||
insta::assert_snapshot!(
|
||||
"working_tip_selected",
|
||||
crate::chatwidget::tests::helpers::normalize_snapshot_paths(buffer_text(
|
||||
crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal),
|
||||
))
|
||||
);
|
||||
app.transcript_view.jump_to_latest();
|
||||
app.chat_widget
|
||||
.on_rate_limit_snapshot(Some(serde_json::from_value(serde_json::json!({
|
||||
@@ -473,6 +552,11 @@ async fn working_tip_stays_put_through_mouse_selection() -> Result<()> {
|
||||
))
|
||||
.contains("└ Tip:")
|
||||
);
|
||||
{
|
||||
let mut selection = app.chat_widget.rendered_selection.borrow_mut();
|
||||
let crate::rendered_selection::RenderedSelection { view, cells, .. } = &mut *selection;
|
||||
assert_eq!(view.selected_text(cells), None);
|
||||
}
|
||||
server.shutdown().await?;
|
||||
tui.set_owned_screen(/*owned*/ false)?;
|
||||
Ok(())
|
||||
|
||||
@@ -14,15 +14,16 @@ use crate::terminal_hyperlinks::HyperlinkParagraph;
|
||||
|
||||
pub(crate) struct TurnTip {
|
||||
pub(crate) line: HyperlinkLine,
|
||||
pub(crate) rendered: Cell<bool>,
|
||||
pub(crate) rendered: Cell<Option<Rect>>,
|
||||
}
|
||||
|
||||
impl Renderable for TurnTip {
|
||||
fn render(&self, area: Rect, buf: &mut Buffer) {
|
||||
if !area.is_empty() && self.line.width() <= usize::from(area.width) {
|
||||
let area = Rect { height: 1, ..area }.intersection(buf.area);
|
||||
HyperlinkParagraph::new(std::slice::from_ref(&self.line), Style::default())
|
||||
.render(Rect { height: 1, ..area }, buf);
|
||||
self.rendered.set(/*val*/ true);
|
||||
.render(area, buf);
|
||||
self.rendered.set(Some(area));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user