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:
parent
93989c035f
commit
5992b81850
@ -94,28 +94,32 @@ class KeyHintView(QLabel):
|
|||||||
self.hide()
|
self.hide()
|
||||||
return
|
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()
|
self.show()
|
||||||
suffix_color = html.escape(config.get('colors', 'keyhint.fg.suffix'))
|
suffix_color = html.escape(config.get('colors', 'keyhint.fg.suffix'))
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
keyconf = objreg.get('key-config')
|
for key, cmd in bindings:
|
||||||
# this is only fired in normal mode
|
text += (
|
||||||
for key, cmd in keyconf.get_bindings_for(modename).items():
|
"<tr>"
|
||||||
# for now, special keys can't be part of keychains, so ignore them
|
"<td>{}</td>"
|
||||||
is_special_binding = key.startswith('<') and key.endswith('>')
|
"<td style='color: {}'>{}</td>"
|
||||||
if key.startswith(prefix) and not is_special_binding:
|
"<td style='padding-left: 2ex'>{}</td>"
|
||||||
text += (
|
"</tr>"
|
||||||
"<tr>"
|
).format(
|
||||||
"<td>{}</td>"
|
html.escape(prefix),
|
||||||
"<td style='color: {}'>{}</td>"
|
suffix_color,
|
||||||
"<td style='padding-left: 2ex'>{}</td>"
|
html.escape(key[len(prefix):]),
|
||||||
"</tr>"
|
html.escape(cmd)
|
||||||
).format(
|
)
|
||||||
html.escape(prefix),
|
|
||||||
suffix_color,
|
|
||||||
html.escape(key[len(prefix):]),
|
|
||||||
html.escape(cmd)
|
|
||||||
)
|
|
||||||
text = '<table>{}</table>'.format(text)
|
text = '<table>{}</table>'.format(text)
|
||||||
|
|
||||||
self.setText(text)
|
self.setText(text)
|
||||||
|
@ -110,3 +110,11 @@ def test_color_switch(keyhint, config_stub, key_config_stub):
|
|||||||
('aa', 'cmd-aa')]))
|
('aa', 'cmd-aa')]))
|
||||||
keyhint.update_keyhint('normal', 'a')
|
keyhint.update_keyhint('normal', 'a')
|
||||||
assert keyhint.text() == expected_text(('a', '#ABCDEF', 'a', 'cmd-aa'))
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user