Edit the spacing in shortcuts (#4330)
<img width="739" height="132" alt="image" src="https://github.com/user-attachments/assets/e8d40abb-ac41-49a2-abc4-ddc6decef989" />
This commit is contained in:
@@ -1204,17 +1204,25 @@ impl ChatComposer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_shortcut_overlay_key(&mut self, key_event: &KeyEvent) -> bool {
|
fn handle_shortcut_overlay_key(&mut self, key_event: &KeyEvent) -> bool {
|
||||||
if key_event.kind == KeyEventKind::Press
|
if key_event.kind != KeyEventKind::Press {
|
||||||
&& key_event.modifiers.is_empty()
|
return false;
|
||||||
&& 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
fn footer_props(&self) -> FooterProps {
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ fn build_columns(entries: Vec<String>) -> Vec<Line<'static>> {
|
|||||||
|
|
||||||
const COLUMNS: usize = 3;
|
const COLUMNS: usize = 3;
|
||||||
const MAX_PADDED_WIDTHS: [usize; COLUMNS - 1] = [24, 28];
|
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 rows = entries.len().div_ceil(COLUMNS);
|
||||||
let mut column_widths = [0usize; COLUMNS];
|
let mut column_widths = [0usize; COLUMNS];
|
||||||
@@ -160,7 +161,8 @@ fn build_columns(entries: Vec<String>) -> Vec<Line<'static>> {
|
|||||||
let entry = &entries[idx];
|
let entry = &entries[idx];
|
||||||
if col < COLUMNS - 1 {
|
if col < COLUMNS - 1 {
|
||||||
let max_width = MAX_PADDED_WIDTHS[col];
|
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;
|
let pad_width = target_width + 2;
|
||||||
line.push_str(&format!("{entry:<pad_width$}"));
|
line.push_str(&format!("{entry:<pad_width$}"));
|
||||||
} else {
|
} else {
|
||||||
@@ -179,13 +181,13 @@ fn build_columns(entries: Vec<String>) -> Vec<Line<'static>> {
|
|||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
enum ShortcutId {
|
enum ShortcutId {
|
||||||
Commands,
|
Commands,
|
||||||
FilePaths,
|
|
||||||
InsertNewline,
|
InsertNewline,
|
||||||
|
ChangeMode,
|
||||||
|
FilePaths,
|
||||||
PasteImage,
|
PasteImage,
|
||||||
|
EditPrevious,
|
||||||
Quit,
|
Quit,
|
||||||
ShowTranscript,
|
ShowTranscript,
|
||||||
ToggleOverlay,
|
|
||||||
EditPrevious,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
@@ -272,17 +274,6 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
|
|||||||
prefix: "",
|
prefix: "",
|
||||||
label: " for commands",
|
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 {
|
ShortcutDescriptor {
|
||||||
id: ShortcutId::InsertNewline,
|
id: ShortcutId::InsertNewline,
|
||||||
bindings: &[
|
bindings: &[
|
||||||
@@ -302,6 +293,28 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
|
|||||||
prefix: "",
|
prefix: "",
|
||||||
label: " for newline",
|
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 {
|
ShortcutDescriptor {
|
||||||
id: ShortcutId::PasteImage,
|
id: ShortcutId::PasteImage,
|
||||||
bindings: &[ShortcutBinding {
|
bindings: &[ShortcutBinding {
|
||||||
@@ -313,6 +326,17 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
|
|||||||
prefix: "",
|
prefix: "",
|
||||||
label: " to paste images",
|
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 {
|
ShortcutDescriptor {
|
||||||
id: ShortcutId::Quit,
|
id: ShortcutId::Quit,
|
||||||
bindings: &[ShortcutBinding {
|
bindings: &[ShortcutBinding {
|
||||||
@@ -335,28 +359,6 @@ const SHORTCUTS: &[ShortcutDescriptor] = &[
|
|||||||
prefix: "",
|
prefix: "",
|
||||||
label: " to view transcript",
|
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)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ expression: terminal.backend()
|
|||||||
" "
|
" "
|
||||||
" "
|
" "
|
||||||
" "
|
" "
|
||||||
" / for commands @ for file paths shift + enter for newline "
|
" / for commands shift + enter for newline shift + tab to change mode "
|
||||||
" ctrl + v to paste images ctrl + c to exit ctrl + t to view transcript "
|
" @ for file paths ctrl + v to paste images esc again to edit previous message "
|
||||||
" ? to hide shortcuts esc again to edit previous message "
|
" ctrl + c to exit ctrl + t to view transcript "
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
source: tui/src/bottom_pane/footer.rs
|
source: tui/src/bottom_pane/footer.rs
|
||||||
expression: terminal.backend()
|
expression: terminal.backend()
|
||||||
---
|
---
|
||||||
" / for commands @ for file paths shift + enter for ne"
|
" / for commands shift + enter for newline shift + tab to change m"
|
||||||
" ctrl + v to paste images ctrl + c to exit ctrl + t to view tra"
|
" @ for file paths ctrl + v to paste images esc again to edit previ"
|
||||||
" ? to hide shortcuts esc again to edit previous message "
|
" ctrl + c to exit ctrl + t to view transcript "
|
||||||
|
|||||||
Reference in New Issue
Block a user