mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Restore hidden sidebars with the workspace shortcut (#64253)
## Why The sidebar shortcut can hide an open sidebar, but pressing it again can fail to bring back the content the user was viewing. ## What changed Make the default `Ctrl+X`, `s` shortcut restore hidden sidebar content and show “Restore sidebar” in the shortcut guide. Hide the previous and next tab hints when there is no other tab to switch to, and show “Pane right” when focus can move from the main pane to an open sidebar panel. ## Testing Extend the sidebar tests to verify that the shortcut restores the same document with its updated text. Snapshot the restore hint and the directional hints shown when switching focus between panes. GitOrigin-RevId: 1093039deb8390ca532ae00613c7c0e7ceb29b5c
This commit is contained in:
@@ -389,6 +389,8 @@ impl App {
|
|||||||
self.step_sidebar_tab(tui, app_server, step).await
|
self.step_sidebar_tab(tui, app_server, step).await
|
||||||
} else if tabs {
|
} else if tabs {
|
||||||
self.open_sidebar_tabs(tui, app_server).await
|
self.open_sidebar_tabs(tui, app_server).await
|
||||||
|
} else if sidebar && self.sidebar_is_hidden() {
|
||||||
|
self.restore_sidebar(tui, app_server).await
|
||||||
} else if resize {
|
} else if resize {
|
||||||
self.begin_pane_resize(tui)
|
self.begin_pane_resize(tui)
|
||||||
} else if let Some(percent) = focused_percent {
|
} else if let Some(percent) = focused_percent {
|
||||||
|
|||||||
@@ -887,6 +887,28 @@ size 123
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert!(app.sidebar().unwrap().visible_content() == document);
|
assert!(app.sidebar().unwrap().visible_content() == document);
|
||||||
|
|
||||||
|
// Repeat the pointer round trip with the default workspace shortcut.
|
||||||
|
app.local_settings.tui.keymap = Default::default();
|
||||||
|
enable_side_retention(&mut app)?;
|
||||||
|
let leader = KeyEvent::new(KeyCode::Char('x'), KeyModifiers::CONTROL);
|
||||||
|
let toggle = KeyEvent::from(KeyCode::Char('s'));
|
||||||
|
for key in [leader, toggle, leader] {
|
||||||
|
Box::pin(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Key(key))).await?;
|
||||||
|
}
|
||||||
|
tokio::time::pause();
|
||||||
|
tokio::time::advance(crate::keymap::CHORD_REVEAL_DELAY).await;
|
||||||
|
side_frame(&mut app, &mut tui, Size::new(size.width, /*height*/ 30))?;
|
||||||
|
let hud = tui.shortcut_hud_area.expect("workspace shortcuts");
|
||||||
|
let guide = (hud.y..hud.bottom())
|
||||||
|
.map(|row| visible_sidebar_row(&tui, hud, row))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n");
|
||||||
|
insta::assert_snapshot!("restore_hidden_sidebar_guide", guide);
|
||||||
|
tokio::time::resume();
|
||||||
|
Box::pin(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Key(toggle))).await?;
|
||||||
|
assert!(app.sidebar().unwrap().visible_content() == document);
|
||||||
|
assert!(side_frame(&mut app, &mut tui, size)?.contains("Updated ending."));
|
||||||
server.shutdown().await?;
|
server.shutdown().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ use super::*;
|
|||||||
use crate::sidebar_tab_strip::SidebarTab;
|
use crate::sidebar_tab_strip::SidebarTab;
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
pub(super) fn sidebar_is_hidden(&self) -> bool {
|
||||||
|
self.sidebar()
|
||||||
|
.and_then(sidebar::SidebarPane::hidden_content)
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
/// Hide the sidebar while returning input to its parent conversation.
|
/// Hide the sidebar while returning input to its parent conversation.
|
||||||
pub(super) async fn hide_sidebar(
|
pub(super) async fn hide_sidebar(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -64,9 +70,7 @@ impl App {
|
|||||||
tui.frame_requester().schedule_frame();
|
tui.frame_requester().schedule_frame();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let hidden = self
|
let hidden = self.sidebar_is_hidden();
|
||||||
.sidebar()
|
|
||||||
.is_some_and(|pane| pane.hidden_content().is_some());
|
|
||||||
let agent = (tab == SidebarTab::Subagents)
|
let agent = (tab == SidebarTab::Subagents)
|
||||||
.then(|| self.sidebar().and_then(|pane| pane.agents.detail))
|
.then(|| self.sidebar().and_then(|pane| pane.agents.detail))
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/app/sidebar_document_tests.rs
|
||||||
|
expression: guide
|
||||||
|
---
|
||||||
|
─ ⌃x · Conversation ────────────────────────────────────────
|
||||||
|
|
||||||
|
Panes
|
||||||
|
c Main composer
|
||||||
|
s Restore sidebar
|
||||||
|
t Open in sidebar
|
||||||
|
a Command Center
|
||||||
|
|
||||||
|
This pane
|
||||||
|
[ Select transcript
|
||||||
|
p Presets ›
|
||||||
|
|
||||||
|
Esc cancel
|
||||||
@@ -1493,6 +1493,34 @@ async fn sidebar_chooser_preserves_the_parent_draft_and_starts_a_side_chat() ->
|
|||||||
if key == KeyCode::Esc {
|
if key == KeyCode::Esc {
|
||||||
let frame = super::side_frame(&mut app, &mut tui, size)?;
|
let frame = super::side_frame(&mut app, &mut tui, size)?;
|
||||||
insta::assert_snapshot!("sidebar_new_chat", frame);
|
insta::assert_snapshot!("sidebar_new_chat", frame);
|
||||||
|
let mut destinations = Vec::new();
|
||||||
|
for direction in ['h', 'l'] {
|
||||||
|
Box::pin(press(&mut app, &mut tui, &mut server, ctrl('x'))).await?;
|
||||||
|
tokio::time::advance(crate::keymap::CHORD_REVEAL_DELAY).await;
|
||||||
|
let frame = super::side_frame(
|
||||||
|
&mut app,
|
||||||
|
&mut tui,
|
||||||
|
ratatui::layout::Size::new(size.width, /*height*/ 24),
|
||||||
|
)?;
|
||||||
|
let labels = ["Pane left", "Pane right", "Previous tab", "Next tab"]
|
||||||
|
.into_iter()
|
||||||
|
.filter(|label| frame.contains(*label))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
destinations.push(labels);
|
||||||
|
Box::pin(press(
|
||||||
|
&mut app,
|
||||||
|
&mut tui,
|
||||||
|
&mut server,
|
||||||
|
KeyCode::Char(direction).into(),
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
insta::assert_snapshot!(destinations.join("\n"), @"
|
||||||
|
Pane left
|
||||||
|
Pane right
|
||||||
|
");
|
||||||
|
super::side_frame(&mut app, &mut tui, size)?;
|
||||||
app.begin_pane_resize(&mut tui)?;
|
app.begin_pane_resize(&mut tui)?;
|
||||||
let resizing = super::side_frame(&mut app, &mut tui, size)?;
|
let resizing = super::side_frame(&mut app, &mut tui, size)?;
|
||||||
let footer = resizing.lines().last().unwrap().split_once('│').unwrap().1;
|
let footer = resizing.lines().last().unwrap().split_once('│').unwrap().1;
|
||||||
|
|||||||
@@ -27,7 +27,14 @@ impl App {
|
|||||||
let center = self.workspace_center_owns_input();
|
let center = self.workspace_center_owns_input();
|
||||||
let center_open = self.agents_overview.workspace.is_open();
|
let center_open = self.agents_overview.workspace.is_open();
|
||||||
let side = !center && self.sidebar_has_focus();
|
let side = !center && self.sidebar_has_focus();
|
||||||
let can_switch = self.panel_focus().is_some() || self.switchable_side_child().is_some();
|
let panel_open = self.panel_focus().is_some();
|
||||||
|
let can_switch = panel_open || self.switchable_side_child().is_some();
|
||||||
|
let can_step = self.sidebar().is_some_and(|pane| {
|
||||||
|
pane.adjacent_tab(/*step*/ 1).is_some_and(|next| {
|
||||||
|
self.chooser_focus().is_some()
|
||||||
|
|| Some(next) != pane.recent_tab(/*excluding*/ None)
|
||||||
|
})
|
||||||
|
});
|
||||||
let can_size = super::side_pane::split_layout(self, tui, area).is_some();
|
let can_size = super::side_pane::split_layout(self, tui, area).is_some();
|
||||||
let can_resize = can_size && side && self.zoomed_thread.is_none();
|
let can_resize = can_size && side && self.zoomed_thread.is_none();
|
||||||
let mut groups = [
|
let mut groups = [
|
||||||
@@ -41,6 +48,7 @@ impl App {
|
|||||||
"focus_main_composer" => (0, "Main composer"),
|
"focus_main_composer" => (0, "Main composer"),
|
||||||
"focus_sidebar_tabs" => (0, "Open in sidebar"),
|
"focus_sidebar_tabs" => (0, "Open in sidebar"),
|
||||||
"focus_sidebar_content" if side => (0, "Hide sidebar"),
|
"focus_sidebar_content" if side => (0, "Hide sidebar"),
|
||||||
|
"focus_sidebar_content" if self.sidebar_is_hidden() => (0, "Restore sidebar"),
|
||||||
"focus_sidebar_content" => (0, "Sidebar content"),
|
"focus_sidebar_content" => (0, "Sidebar content"),
|
||||||
"resize_panes" if can_size => (2, "Resize panes"),
|
"resize_panes" if can_size => (2, "Resize panes"),
|
||||||
"resize_panes" => continue,
|
"resize_panes" => continue,
|
||||||
@@ -57,6 +65,7 @@ impl App {
|
|||||||
(2, "Close tab")
|
(2, "Close tab")
|
||||||
}
|
}
|
||||||
"close_sidebar_tab" => continue,
|
"close_sidebar_tab" => continue,
|
||||||
|
"sidebar_up" | "sidebar_down" if !can_step => continue,
|
||||||
"sidebar_up" => (1, "Previous tab"),
|
"sidebar_up" => (1, "Previous tab"),
|
||||||
"sidebar_down" => (1, "Next tab"),
|
"sidebar_down" => (1, "Next tab"),
|
||||||
"hide_pane" if side => (2, "Hide pane"),
|
"hide_pane" if side => (2, "Hide pane"),
|
||||||
@@ -64,7 +73,10 @@ impl App {
|
|||||||
(1, "Pane left")
|
(1, "Pane left")
|
||||||
}
|
}
|
||||||
"focus_pane_right"
|
"focus_pane_right"
|
||||||
if center || (!side && can_switch && self.open_pane_focus().is_some()) =>
|
if center
|
||||||
|
|| (!side
|
||||||
|
&& (panel_open
|
||||||
|
|| (can_switch && self.open_pane_focus().is_some()))) =>
|
||||||
{
|
{
|
||||||
(1, "Pane right")
|
(1, "Pane right")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user