From 6b48624b81e43fb47b2d389a67daacaaf93afea9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 6 Nov 2022 11:44:20 +0530 Subject: [PATCH] Reset keyboard state when resetting text --- tools/tui/readline/api.go | 1 + tools/tui/readline/keys.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/tui/readline/api.go b/tools/tui/readline/api.go index bb5c90fbe..0834a10d3 100644 --- a/tools/tui/readline/api.go +++ b/tools/tui/readline/api.go @@ -203,6 +203,7 @@ func (self *Readline) ResetText() { self.cursor = Position{} self.cursor_y = 0 self.last_action = ActionNil + self.keyboard_state = KeyboardState{} } func (self *Readline) ChangeLoopAndResetText(lp *loop.Loop) { diff --git a/tools/tui/readline/keys.go b/tools/tui/readline/keys.go index 9ff7a6b50..f035845f4 100644 --- a/tools/tui/readline/keys.go +++ b/tools/tui/readline/keys.go @@ -19,7 +19,7 @@ type ShortcutMap struct { } type KeyboardState struct { - shortcut_maps []*ShortcutMap + active_shortcut_maps []*ShortcutMap current_pending_keys []string current_numeric_argument string } @@ -164,13 +164,13 @@ func (self *Readline) dispatch_key_action(ac Action) error { } func (self *Readline) handle_key_event(event *loop.KeyEvent) error { - if len(self.keyboard_state.shortcut_maps) == 0 { - self.keyboard_state.shortcut_maps = []*ShortcutMap{default_shortcuts()} - } if event.Text != "" { return nil } - sm := self.keyboard_state.shortcut_maps[len(self.keyboard_state.shortcut_maps)-1] + sm := default_shortcuts() + if len(self.keyboard_state.active_shortcut_maps) > 0 { + sm = self.keyboard_state.active_shortcut_maps[len(self.keyboard_state.active_shortcut_maps)-1] + } for _, pk := range self.keyboard_state.current_pending_keys { sm = sm.children[pk] }