From 74366d895d5c5cce5c14424926bb5de229894884 Mon Sep 17 00:00:00 2001 From: kt programs Date: Mon, 14 Mar 2022 11:03:34 +0800 Subject: viewer: add key passthrough mode When trying to search in less, keys bound to viewer functions can't be used as part of the search query, which makes the search useless. Add a view::passthrough binding mode and a :toggle-key-passthrough command go toggle in and out of that mode. By default, typing '/' in the viewer is bound to enabling key passthrough and automatically inserting '/', to easily enter "less" search mode. When in the passthrough mode, all bindings are ignored by default. The default binds.conf only defines a single keybinding in that mode: to get back out. $ex is bound to to allow typing colons. Signed-off-by: Kt Programs Acked-by: Robin Jarry --- commands/msgview/toggle-key-passthrough.go | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 commands/msgview/toggle-key-passthrough.go (limited to 'commands') diff --git a/commands/msgview/toggle-key-passthrough.go b/commands/msgview/toggle-key-passthrough.go new file mode 100644 index 0000000..6cd575b --- /dev/null +++ b/commands/msgview/toggle-key-passthrough.go @@ -0,0 +1,35 @@ +package msgview + +import ( + "errors" + + "git.sr.ht/~rjarry/aerc/widgets" +) + +type ToggleKeyPassthrough struct{} + +func init() { + register(ToggleKeyPassthrough{}) +} + +func (ToggleKeyPassthrough) Aliases() []string { + return []string{"toggle-key-passthrough"} +} + +func (ToggleKeyPassthrough) Complete(aerc *widgets.Aerc, args []string) []string { + return nil +} + +func (ToggleKeyPassthrough) Execute(aerc *widgets.Aerc, args []string) error { + if len(args) != 1 { + return errors.New("Usage: toggle-key-passthrough") + } + mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) + keyPassthroughEnabled := mv.ToggleKeyPassthrough() + if keyPassthroughEnabled { + aerc.SetExtraStatus("[passthrough]") + } else { + aerc.ClearExtraStatus() + } + return nil +} -- cgit v1.2.3