summaryrefslogtreecommitdiff
path: root/qutebrowser/config/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/config/config.py')
-rw-r--r--qutebrowser/config/config.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py
index c644725b5..07d16ea92 100644
--- a/qutebrowser/config/config.py
+++ b/qutebrowser/config/config.py
@@ -27,6 +27,7 @@ from typing import (TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Mapping,
from PyQt5.QtCore import pyqtSignal, QObject, QUrl
+from qutebrowser.commands import cmdexc, parser
from qutebrowser.config import configdata, configexc, configutils
from qutebrowser.utils import utils, log, urlmatch
from qutebrowser.misc import objects
@@ -162,13 +163,38 @@ class KeyConfig:
bindings[key] = binding
return bindings
+ def _implied_cmd(self, cmdline: str) -> Optional[str]:
+ """Return cmdline, or the implied cmd if cmdline is a set-cmd-text."""
+ try:
+ results = parser.CommandParser().parse_all(cmdline)
+ except cmdexc.NoSuchCommandError:
+ return None
+
+ result = results[0]
+ if result.cmd.name != "set-cmd-text":
+ return cmdline
+ *flags, cmd = result.args
+ if "-a" in flags or "--append" in flags or not cmd.startswith(":"):
+ return None # doesn't look like this sets a command
+ return cmd.lstrip(":")
+
def get_reverse_bindings_for(self, mode: str) -> '_ReverseBindings':
- """Get a dict of commands to a list of bindings for the mode."""
+ """Get a dict of commands to a list of bindings for the mode.
+
+ This is intented for user-facing display of keybindings.
+ As such, bindings for 'set-cmd-text [flags] :<cmd> ...' are translated
+ to '<cmd> ...', as from the user's perspective these keys behave like
+ bindings for '<cmd>' (that allow for further input before running).
+
+ See #5942.
+ """
cmd_to_keys: KeyConfig._ReverseBindings = {}
bindings = self.get_bindings_for(mode)
for seq, full_cmd in sorted(bindings.items()):
- for cmd in full_cmd.split(';;'):
- cmd = cmd.strip()
+ for cmdtext in full_cmd.split(';;'):
+ cmd = self._implied_cmd(cmdtext.strip())
+ if not cmd:
+ continue
cmd_to_keys.setdefault(cmd, [])
# Put bindings involving modifiers last
if any(info.modifiers for info in seq):