Fix esc (#2661)
Esc should have other functionalities when it's not used in a backtracking situation. i.e. to cancel pop up menu when selecting model/approvals or to interrupt an active turn.
This commit is contained in:
@@ -303,13 +303,21 @@ impl App {
|
|||||||
self.transcript_overlay = Some(TranscriptApp::new(self.transcript_lines.clone()));
|
self.transcript_overlay = Some(TranscriptApp::new(self.transcript_lines.clone()));
|
||||||
tui.frame_requester().schedule_frame();
|
tui.frame_requester().schedule_frame();
|
||||||
}
|
}
|
||||||
// Esc primes/advances backtracking when composer is empty.
|
// Esc primes/advances backtracking only in normal (not working) mode
|
||||||
|
// with an empty composer. In any other state, forward Esc so the
|
||||||
|
// active UI (e.g. status indicator, modals, popups) handles it.
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
code: KeyCode::Esc,
|
code: KeyCode::Esc,
|
||||||
kind: KeyEventKind::Press | KeyEventKind::Repeat,
|
kind: KeyEventKind::Press | KeyEventKind::Repeat,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
self.handle_backtrack_esc_key(tui);
|
if self.chat_widget.is_normal_backtrack_mode()
|
||||||
|
&& self.chat_widget.composer_is_empty()
|
||||||
|
{
|
||||||
|
self.handle_backtrack_esc_key(tui);
|
||||||
|
} else {
|
||||||
|
self.chat_widget.handle_key_event(key_event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Enter confirms backtrack when primed + count > 0. Otherwise pass to widget.
|
// Enter confirms backtrack when primed + count > 0. Otherwise pass to widget.
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
|
|||||||
@@ -307,6 +307,11 @@ impl ChatComposer {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return true if either the slash-command popup or the file-search popup is active.
|
||||||
|
pub(crate) fn popup_active(&self) -> bool {
|
||||||
|
!matches!(self.active_popup, ActivePopup::None)
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle key event when the slash-command popup is visible.
|
/// Handle key event when the slash-command popup is visible.
|
||||||
fn handle_key_event_with_slash_popup(&mut self, key_event: KeyEvent) -> (InputResult, bool) {
|
fn handle_key_event_with_slash_popup(&mut self, key_event: KeyEvent) -> (InputResult, bool) {
|
||||||
let ActivePopup::Command(popup) = &mut self.active_popup else {
|
let ActivePopup::Command(popup) = &mut self.active_popup else {
|
||||||
@@ -327,6 +332,13 @@ impl ChatComposer {
|
|||||||
popup.move_down();
|
popup.move_down();
|
||||||
(InputResult::None, true)
|
(InputResult::None, true)
|
||||||
}
|
}
|
||||||
|
KeyEvent {
|
||||||
|
code: KeyCode::Esc, ..
|
||||||
|
} => {
|
||||||
|
// Dismiss the slash popup; keep the current input untouched.
|
||||||
|
self.active_popup = ActivePopup::None;
|
||||||
|
(InputResult::None, true)
|
||||||
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
code: KeyCode::Tab, ..
|
code: KeyCode::Tab, ..
|
||||||
} => {
|
} => {
|
||||||
|
|||||||
@@ -337,6 +337,13 @@ impl BottomPane {
|
|||||||
self.is_task_running
|
self.is_task_running
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return true when the pane is in the regular composer state without any
|
||||||
|
/// overlays or popups and not running a task. This is the safe context to
|
||||||
|
/// use Esc-Esc for backtracking from the main view.
|
||||||
|
pub(crate) fn is_normal_backtrack_mode(&self) -> bool {
|
||||||
|
!self.is_task_running && self.active_view.is_none() && !self.composer.popup_active()
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the *context-window remaining* indicator in the composer. This
|
/// Update the *context-window remaining* indicator in the composer. This
|
||||||
/// is forwarded directly to the underlying `ChatComposer`.
|
/// is forwarded directly to the underlying `ChatComposer`.
|
||||||
pub(crate) fn set_token_usage(
|
pub(crate) fn set_token_usage(
|
||||||
|
|||||||
@@ -1125,6 +1125,13 @@ impl ChatWidget {
|
|||||||
self.bottom_pane.composer_is_empty()
|
self.bottom_pane.composer_is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True when the UI is in the regular composer state with no running task,
|
||||||
|
/// no modal overlay (e.g. approvals or status indicator), and no composer popups.
|
||||||
|
/// In this state Esc-Esc backtracking is enabled.
|
||||||
|
pub(crate) fn is_normal_backtrack_mode(&self) -> bool {
|
||||||
|
self.bottom_pane.is_normal_backtrack_mode()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn insert_str(&mut self, text: &str) {
|
pub(crate) fn insert_str(&mut self, text: &str) {
|
||||||
self.bottom_pane.insert_str(text);
|
self.bottom_pane.insert_str(text);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user