Don't show keyhint if there are no hints.

Currently, the keyhint window is shown even if the keystring matches no
possible bindings. This causes an empty keyhint window to hang around
after entering hinting mode.

Instead, the window is now hidden if no bindings match the current
keystring.

Resolves #1507.
This commit is contained in:
Ryan Roden-Corrent 2016-05-18 21:54:20 -04:00
parent 93989c035f
commit 5992b81850
2 changed files with 30 additions and 18 deletions

View File

@ -94,28 +94,32 @@ class KeyHintView(QLabel):
self.hide()
return
keyconf = objreg.get('key-config')
is_special = lambda k: k.startswith('<') and k.endswith('>')
bindings = [(key, cmd) for (key, cmd)
in keyconf.get_bindings_for(modename).items()
if key.startswith(prefix) and not is_special(key)]
if not bindings:
return
self.show()
suffix_color = html.escape(config.get('colors', 'keyhint.fg.suffix'))
text = ''
keyconf = objreg.get('key-config')
# this is only fired in normal mode
for key, cmd in keyconf.get_bindings_for(modename).items():
# for now, special keys can't be part of keychains, so ignore them
is_special_binding = key.startswith('<') and key.endswith('>')
if key.startswith(prefix) and not is_special_binding:
text += (
"<tr>"
"<td>{}</td>"
"<td style='color: {}'>{}</td>"
"<td style='padding-left: 2ex'>{}</td>"
"</tr>"
).format(
html.escape(prefix),
suffix_color,
html.escape(key[len(prefix):]),
html.escape(cmd)
)
for key, cmd in bindings:
text += (
"<tr>"
"<td>{}</td>"
"<td style='color: {}'>{}</td>"
"<td style='padding-left: 2ex'>{}</td>"
"</tr>"
).format(
html.escape(prefix),
suffix_color,
html.escape(key[len(prefix):]),
html.escape(cmd)
)
text = '<table>{}</table>'.format(text)
self.setText(text)

View File

@ -110,3 +110,11 @@ def test_color_switch(keyhint, config_stub, key_config_stub):
('aa', 'cmd-aa')]))
keyhint.update_keyhint('normal', 'a')
assert keyhint.text() == expected_text(('a', '#ABCDEF', 'a', 'cmd-aa'))
def test_no_matches(keyhint, key_config_stub):
"""Ensure the widget isn't visible if there are no keystrings to show."""
key_config_stub.set_bindings_for('normal', OrderedDict([
('aa', 'cmd-aa'),
('ab', 'cmd-ab')]))
keyhint.update_keyhint('normal', 'z')
assert not keyhint.isVisible()