Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions codex-rs/tui/src/bottom_pane/chat_composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,17 +1204,25 @@ impl ChatComposer {
}

fn handle_shortcut_overlay_key(&mut self, key_event: &KeyEvent) -> bool {
if key_event.kind == KeyEventKind::Press
&& key_event.modifiers.is_empty()
&& matches!(key_event.code, KeyCode::Char('?'))
{
let next = toggle_shortcut_mode(self.footer_mode, self.ctrl_c_quit_hint);
let changed = next != self.footer_mode;
self.footer_mode = next;
changed
} else {
false
if key_event.kind != KeyEventKind::Press {
return false;
}

let toggles = match key_event.code {
KeyCode::Char('?') if key_event.modifiers.is_empty() => true,
KeyCode::BackTab => true,
KeyCode::Tab if key_event.modifiers.contains(KeyModifiers::SHIFT) => true,
_ => false,
};

if !toggles {
return false;
}

let next = toggle_shortcut_mode(self.footer_mode, self.ctrl_c_quit_hint);
let changed = next != self.footer_mode;
self.footer_mode = next;
changed
}

fn footer_props(&self) -> FooterProps {
Expand Down
76 changes: 39 additions & 37 deletions codex-rs/tui/src/bottom_pane/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ fn build_columns(entries: Vec<String>) -> Vec<Line<'static>> {

const COLUMNS: usize = 3;
const MAX_PADDED_WIDTHS: [usize; COLUMNS - 1] = [24, 28];
const MIN_PADDED_WIDTHS: [usize; COLUMNS - 1] = [22, 0];

let rows = entries.len().div_ceil(COLUMNS);
let mut column_widths = [0usize; COLUMNS];
Expand All @@ -160,7 +161,8 @@ fn build_columns(entries: Vec<String>) -> Vec<Line<'static>> {
let entry = &entries[idx];
if col < COLUMNS - 1 {
let max_width = MAX_PADDED_WIDTHS[col];
let target_width = column_widths[col].min(max_width);
let mut target_width = column_widths[col];
target_width = target_width.max(MIN_PADDED_WIDTHS[col]).min(max_width);
let pad_width = target_width + 2;
line.push_str(&format!("{entry:<pad_width$}"));
} else {
Expand All @@ -179,13 +181,13 @@ fn build_columns(entries: Vec<String>) -> Vec<Line<'static>> {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum ShortcutId {
Commands,
FilePaths,
InsertNewline,
ChangeMode,
FilePaths,
PasteImage,
EditPrevious,
Quit,
ShowTranscript,
ToggleOverlay,
EditPrevious,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -272,17 +274,6 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
prefix: "",
label: " for commands",
},
ShortcutDescriptor {
id: ShortcutId::FilePaths,
bindings: &[ShortcutBinding {
code: KeyCode::Char('@'),
modifiers: KeyModifiers::NONE,
overlay_text: "@",
condition: DisplayCondition::Always,
}],
prefix: "",
label: " for file paths",
},
ShortcutDescriptor {
id: ShortcutId::InsertNewline,
bindings: &[
Expand All @@ -302,6 +293,28 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
prefix: "",
label: " for newline",
},
ShortcutDescriptor {
id: ShortcutId::ChangeMode,
bindings: &[ShortcutBinding {
code: KeyCode::BackTab,
modifiers: KeyModifiers::SHIFT,
overlay_text: "shift + tab",
condition: DisplayCondition::Always,
}],
prefix: "",
label: " to change mode",
},
ShortcutDescriptor {
id: ShortcutId::FilePaths,
bindings: &[ShortcutBinding {
code: KeyCode::Char('@'),
modifiers: KeyModifiers::NONE,
overlay_text: "@",
condition: DisplayCondition::Always,
}],
prefix: "",
label: " for file paths",
},
ShortcutDescriptor {
id: ShortcutId::PasteImage,
bindings: &[ShortcutBinding {
Expand All @@ -313,6 +326,17 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
prefix: "",
label: " to paste images",
},
ShortcutDescriptor {
id: ShortcutId::EditPrevious,
bindings: &[ShortcutBinding {
code: KeyCode::Esc,
modifiers: KeyModifiers::NONE,
overlay_text: "esc",
condition: DisplayCondition::Always,
}],
prefix: "",
label: "",
},
ShortcutDescriptor {
id: ShortcutId::Quit,
bindings: &[ShortcutBinding {
Expand All @@ -335,28 +359,6 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
prefix: "",
label: " to view transcript",
},
ShortcutDescriptor {
id: ShortcutId::ToggleOverlay,
bindings: &[ShortcutBinding {
code: KeyCode::Char('?'),
modifiers: KeyModifiers::NONE,
overlay_text: "?",
condition: DisplayCondition::Always,
}],
prefix: "",
label: " to hide shortcuts",
},
ShortcutDescriptor {
id: ShortcutId::EditPrevious,
bindings: &[ShortcutBinding {
code: KeyCode::Esc,
modifiers: KeyModifiers::NONE,
overlay_text: "esc",
condition: DisplayCondition::Always,
}],
prefix: "",
label: "",
},
];

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ expression: terminal.backend()
" "
" "
" "
" / for commands @ for file paths shift + enter for newline "
" ctrl + v to paste images ctrl + c to exit ctrl + t to view transcript "
" ? to hide shortcuts esc again to edit previous message "
" / for commands shift + enter for newline shift + tab to change mode "
" @ for file paths ctrl + v to paste images esc again to edit previous message "
" ctrl + c to exit ctrl + t to view transcript "
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
source: tui/src/bottom_pane/footer.rs
expression: terminal.backend()
---
" / for commands @ for file paths shift + enter for ne"
" ctrl + v to paste images ctrl + c to exit ctrl + t to view tra"
" ? to hide shortcuts esc again to edit previous message "
" / for commands shift + enter for newline shift + tab to change m"
" @ for file paths ctrl + v to paste images esc again to edit previ"
" ctrl + c to exit ctrl + t to view transcript "
Loading