summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Albrecht <philipp.albrecht@momox.biz>2021-11-26 15:47:05 +0100
committerPhilipp Albrecht <palbrecht@mailbox.org>2021-11-28 15:50:04 +0100
commitb900f1dd309cf7102d729316edb4c4aa7a5ed9de (patch)
treeeed6b07ee6954d633bdc0f9f7399e6a352adaeac
parenta4213a4bb6245223ac2cb8bc112d3cf6ea086d24 (diff)
downloadqutebrowser-b900f1dd309cf7102d729316edb4c4aa7a5ed9de.tar.gz
qutebrowser-b900f1dd309cf7102d729316edb4c4aa7a5ed9de.zip
Make interpreting number keys as counts configurable
By default numbers are interpreted as counts for bindings. Making this behavior configurable allows for emacs-like bindings, where number keys are passed through.
-rw-r--r--qutebrowser/config/configdata.yml11
-rw-r--r--qutebrowser/keyinput/basekeyparser.py3
-rw-r--r--tests/unit/keyinput/test_basekeyparser.py11
3 files changed, 25 insertions, 0 deletions
diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml
index e034fe8f5..3c5dc6f2f 100644
--- a/qutebrowser/config/configdata.yml
+++ b/qutebrowser/config/configdata.yml
@@ -1794,6 +1794,17 @@ input.media_keys:
On Linux, disabling this also disables Chromium's MPRIS integration.
+input.match_counts:
+ default: true
+ type: Bool
+ desc: >-
+ Interpret number prefixes as counts for bindings.
+
+ This enables for vi-like bindings that can be prefixed with a number to
+ indicate a count.
+ Disabling it allows for emacs-like bindings where number keys are passed
+ through (according to `input.forward_unbound_keys`) instead.
+
## keyhint
keyhint.blacklist:
diff --git a/qutebrowser/keyinput/basekeyparser.py b/qutebrowser/keyinput/basekeyparser.py
index 7e688dab1..4db1d5d76 100644
--- a/qutebrowser/keyinput/basekeyparser.py
+++ b/qutebrowser/keyinput/basekeyparser.py
@@ -254,6 +254,9 @@ class BaseKeyParser(QObject):
def _match_count(self, sequence: keyutils.KeySequence,
dry_run: bool) -> bool:
"""Try to match a key as count."""
+ if not config.val.input.match_counts:
+ return False
+
txt = str(sequence[-1]) # To account for sequences changed above.
if (txt in string.digits and self._supports_count and
not (not self._count and txt == '0')):
diff --git a/tests/unit/keyinput/test_basekeyparser.py b/tests/unit/keyinput/test_basekeyparser.py
index 30ee36301..84068bf47 100644
--- a/tests/unit/keyinput/test_basekeyparser.py
+++ b/tests/unit/keyinput/test_basekeyparser.py
@@ -346,3 +346,14 @@ def test_clear_keystring_empty(qtbot, keyparser):
keyparser._sequence = keyseq('')
with qtbot.assert_not_emitted(keyparser.keystring_updated):
keyparser.clear_keystring()
+
+
+def test_respect_config_when_matching_counts(keyparser, config_stub):
+ """Don't match counts if disabled in the config."""
+ config_stub.val.input.match_counts = False
+
+ info = keyutils.KeyInfo(Qt.Key_1, Qt.NoModifier)
+ keyparser.handle(info.to_event())
+
+ assert not keyparser._sequence
+ assert not keyparser._count