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 --- widgets/aerc.go | 7 ++++++- widgets/msgviewer.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'widgets') diff --git a/widgets/aerc.go b/widgets/aerc.go index 8061f38..cfc4291 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -201,7 +201,12 @@ func (aerc *Aerc) getBindings() *config.KeyBindings { return aerc.conf.MergeContextualBinds(aerc.conf.Bindings.Compose, config.BIND_CONTEXT_ACCOUNT, selectedAccountName, "compose") } case *MessageViewer: - return aerc.conf.MergeContextualBinds(aerc.conf.Bindings.MessageView, config.BIND_CONTEXT_ACCOUNT, selectedAccountName, "view") + switch view.Bindings() { + case "view::passthrough": + return aerc.conf.MergeContextualBinds(aerc.conf.Bindings.MessageViewPassthrough, config.BIND_CONTEXT_ACCOUNT, selectedAccountName, "view::passthrough") + default: + return aerc.conf.MergeContextualBinds(aerc.conf.Bindings.MessageView, config.BIND_CONTEXT_ACCOUNT, selectedAccountName, "view") + } case *Terminal: return aerc.conf.Bindings.Terminal default: diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index da81ec9..9771a90 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -286,6 +286,11 @@ func (mv *MessageViewer) ToggleHeaders() { switcher.Invalidate() } +func (mv *MessageViewer) ToggleKeyPassthrough() bool { + mv.conf.Viewer.KeyPassthrough = !mv.conf.Viewer.KeyPassthrough + return mv.conf.Viewer.KeyPassthrough +} + func (mv *MessageViewer) SelectedMessagePart() *PartInfo { switcher := mv.switcher part := switcher.parts[switcher.selected] @@ -325,6 +330,14 @@ func (mv *MessageViewer) NextPart() { mv.Invalidate() } +func (mv *MessageViewer) Bindings() string { + if mv.conf.Viewer.KeyPassthrough { + return "view::passthrough" + } else { + return "view" + } +} + func (mv *MessageViewer) Close() error { mv.switcher.Cleanup() return nil -- cgit v1.2.3