From 9a38b8d03010644ed0b6bf81786b53b388077a9f Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 6 Dec 2015 16:46:24 +0100 Subject: [PATCH] Notify keys pressed so far of a command This is only noticeable if typing a multi-key command or using a count. Fixes #632. --- documentation/options.md | 8 ++++++++ extension/lib/defaults.coffee | 1 + extension/lib/events.coffee | 31 ++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/documentation/options.md b/documentation/options.md index bba518b..dd619ec 100644 --- a/documentation/options.md +++ b/documentation/options.md @@ -159,6 +159,14 @@ You can also choose to show notifications any way you want by listening for the [notifications]: notifications.md [notification-events]: api.md#the-notification-and-hidenotification-events +### `notify_entered_keys` + +If enabled, a [notification] is shown with the the keys you have entered so far +of a command. This is only noticeable if you type a multi-key shortcut or use a +count. + +[notification]: notifications.md + ### `prevent_target_blank` You might have noticed that some links open in new tabs when you click them. diff --git a/extension/lib/defaults.coffee b/extension/lib/defaults.coffee index f3b2658..63e8e59 100644 --- a/extension/lib/defaults.coffee +++ b/extension/lib/defaults.coffee @@ -131,6 +131,7 @@ options = advanced_options = 'notifications_enabled': true + 'notify_entered_keys': true 'prevent_target_blank': true 'ignore_ctrl_alt': (Services.appinfo.OS == 'WINNT') 'prevent_autofocus_modes': 'normal' diff --git a/extension/lib/events.coffee b/extension/lib/events.coffee index d91183a..8fdbfed 100644 --- a/extension/lib/events.coffee +++ b/extension/lib/events.coffee @@ -44,6 +44,8 @@ class UIEventManager # keyboard input, allowing accesskeys to be used. @popupPassthrough = false + @enteredKeys = new EnteredKeysManager(@window) + addListeners: -> checkPassthrough = (value, event) => target = event.originalTarget @@ -183,7 +185,14 @@ class UIEventManager match = vim._consumeKeyEvent(event, focusType) if match - vim.hideNotification() + if @vimfx.options.notify_entered_keys + if match.type in ['none', 'full'] + @enteredKeys.clear(vim) + else + @enteredKeys.push(vim, match.keyStr, @vimfx.options.timeout) + else + vim.hideNotification() + if match.specialKeys[''] @suppress = false @consumeLateKeydown(vim, event, match, uiEvent) @@ -233,4 +242,24 @@ class UIEventManager mainWindow.setAttribute(HELD_MODIFIERS_ATTRIBUTE, modifiers.split(' ').filter(isHeld).join(' ')) +class EnteredKeysManager + constructor: (@window) -> + @keys = [] + @timeout = null + + clear: (notifier) -> + @keys = [] + @clearTimeout() + notifier.hideNotification() + + push: (notifier, keyStr, duration) -> + @keys.push(keyStr) + @clearTimeout() + notifier.notify(@keys.join('')) + @timeout = @window.setTimeout(@clear.bind(this, notifier), duration) + + clearTimeout: -> + @window.clearTimeout(@timeout) if @timeout? + @timeout = null + module.exports = UIEventManager -- 2.39.3