summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2018-03-07 22:37:10 +0100
committerFlorian Bruhin <git@the-compiler.org>2018-03-07 22:37:10 +0100
commit514138aad23851955503a5e912dc45f278796bda (patch)
tree86f5ab525cc92d47c04768a7b79175f8d190f777
parent34815f5cf815db7909252ec59e090f4dba57ee47 (diff)
downloadqutebrowser-514138aad23851955503a5e912dc45f278796bda.tar.gz
qutebrowser-514138aad23851955503a5e912dc45f278796bda.zip
Allow to bind numbers in keybindings
This mostly reverts 4ef5db1bc4b5205812714a57d29daa59224afe8b for #1966, but fixes #3684 by allowing numbers to be bound again. If the user wants to bind numbers instead of using them for a count, why not let them.
-rw-r--r--qutebrowser/config/configtypes.py9
-rw-r--r--qutebrowser/keyinput/basekeyparser.py20
-rw-r--r--tests/unit/config/test_configtypes.py4
-rw-r--r--tests/unit/keyinput/conftest.py3
-rw-r--r--tests/unit/keyinput/test_basekeyparser.py8
5 files changed, 24 insertions, 20 deletions
diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py
index 217e94505..14855bf03 100644
--- a/qutebrowser/config/configtypes.py
+++ b/qutebrowser/config/configtypes.py
@@ -1654,13 +1654,6 @@ class Key(BaseType):
return None
try:
- seq = keyutils.KeySequence.parse(value)
+ return keyutils.KeySequence.parse(value)
except keyutils.KeyParseError as e:
raise configexc.ValidationError(value, str(e))
-
- for info in seq:
- if Qt.Key_1 <= info.key <= Qt.Key_9 and not info.modifiers:
- raise configexc.ValidationError(
- value, "Numbers are reserved for counts!")
-
- return seq
diff --git a/qutebrowser/keyinput/basekeyparser.py b/qutebrowser/keyinput/basekeyparser.py
index 6ebb0b464..c527b3cde 100644
--- a/qutebrowser/keyinput/basekeyparser.py
+++ b/qutebrowser/keyinput/basekeyparser.py
@@ -139,13 +139,6 @@ class BaseKeyParser(QObject):
self._debug_log("Ignoring, only modifier")
return QKeySequence.NoMatch
- if (txt.isdigit() and self._supports_count and not
- (not self._count and txt == '0')):
- assert len(txt) == 1, txt
- if not dry_run:
- self._count += txt
- return QKeySequence.ExactMatch
-
try:
sequence = self._sequence.append_event(e)
except keyutils.KeyParseError as ex:
@@ -153,7 +146,10 @@ class BaseKeyParser(QObject):
self.clear_keystring()
return QKeySequence.NoMatch
+ # First, try a straightforward match
match, binding = self._match_key(sequence)
+
+ # If that doesn't match, try a key_mapping
if match == QKeySequence.NoMatch:
mapped = sequence.with_mappings(config.val.bindings.key_mappings)
if sequence != mapped:
@@ -162,6 +158,16 @@ class BaseKeyParser(QObject):
match, binding = self._match_key(mapped)
sequence = mapped
+ # If that doesn't match either, try treating it as count.
+ if (match == QKeySequence.NoMatch and
+ txt.isdigit() and
+ self._supports_count and
+ not (not self._count and txt == '0')):
+ assert len(txt) == 1, txt
+ if not dry_run:
+ self._count += txt
+ return QKeySequence.ExactMatch
+
if dry_run:
return match
diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py
index 074a54f23..4dd7837fb 100644
--- a/tests/unit/config/test_configtypes.py
+++ b/tests/unit/config/test_configtypes.py
@@ -2063,11 +2063,13 @@ class TestKey:
('<Control-x>', keyutils.KeySequence.parse('<ctrl+x>')),
('<alt-1>', keyutils.KeySequence.parse('<alt+1>')),
('0', keyutils.KeySequence.parse('0')),
+ ('1', keyutils.KeySequence.parse('1')),
+ ('a1', keyutils.KeySequence.parse('a1')),
])
def test_to_py_valid(self, klass, val, expected):
assert klass().to_py(val) == expected
- @pytest.mark.parametrize('val', ['\U00010000', '<blub>', '1', 'a1'])
+ @pytest.mark.parametrize('val', ['\U00010000', '<blub>'])
def test_to_py_invalid(self, klass, val):
with pytest.raises(configexc.ValidationError):
klass().to_py(val)
diff --git a/tests/unit/keyinput/conftest.py b/tests/unit/keyinput/conftest.py
index 96d07f744..045b62336 100644
--- a/tests/unit/keyinput/conftest.py
+++ b/tests/unit/keyinput/conftest.py
@@ -33,7 +33,8 @@ BINDINGS = {'prompt': {'<Ctrl-a>': 'message-info ctrla',
'ax': 'message-info ax',
'ccc': 'message-info ccc',
'yY': 'yank -s',
- '0': 'message-info 0'},
+ '0': 'message-info 0',
+ '1': 'message-info 1'},
'command': {'foo': 'message-info bar',
'<Ctrl+X>': 'message-info ctrlx'},
'normal': {'a': 'message-info a', 'ba': 'message-info ba'}}
diff --git a/tests/unit/keyinput/test_basekeyparser.py b/tests/unit/keyinput/test_basekeyparser.py
index 581d0b676..947c50592 100644
--- a/tests/unit/keyinput/test_basekeyparser.py
+++ b/tests/unit/keyinput/test_basekeyparser.py
@@ -192,9 +192,11 @@ class TestHandle:
keyparser.execute.assert_called_with('message-info ba', None)
assert not keyparser._sequence
- def test_0_press(self, handle_text, keyparser):
- handle_text(Qt.Key_0)
- keyparser.execute.assert_called_once_with('message-info 0', None)
+ @pytest.mark.parametrize('key, number', [(Qt.Key_0, 0), (Qt.Key_1, 1)])
+ def test_number_press(self, handle_text, keyparser, key, number):
+ handle_text(key)
+ command = 'message-info {}'.format(number)
+ keyparser.execute.assert_called_once_with(command, None)
assert not keyparser._sequence
def test_umlauts(self, handle_text, keyparser, config_stub):