From 81c91812ad1a1c0df7314217e77e1a3cd6fd6da4 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 15 May 2016 15:22:42 +0200 Subject: [PATCH] Don't trigger VimFx commands in some fancy text inputs Fixes #725. --- documentation/api.md | 4 +++- documentation/options.md | 12 ++++++++++++ extension/lib/defaults.coffee | 1 + extension/lib/events-frame.coffee | 4 +++- extension/lib/events.coffee | 7 +++++-- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/documentation/api.md b/documentation/api.md index ab4af3d..0e3e14e 100644 --- a/documentation/api.md +++ b/documentation/api.md @@ -308,7 +308,8 @@ The event is useful for knowing when to update UI showing the current mode. #### The `focusTypeChange` event -Occurs when focusing or blurring any element. +Occurs when focusing or blurring any element. See also the [`blur_timeout`] +pref. `data`: @@ -814,6 +815,7 @@ backwards compatibility will be a priority and won’t be broken until VimFx [autofocus prevention]: options.md#prevent-autofocus [`activatable_element_keys`]: options.md#activatable_element_keys [`adjustable_element_keys`]: options.md#adjustable_element_keys +[`blur_timeout`]: options.md#blur_timeout [`notifications_enabled`]: options.md#notifications_enabled [button]: button.md diff --git a/documentation/options.md b/documentation/options.md index 4f6ef89..4a0013b 100644 --- a/documentation/options.md +++ b/documentation/options.md @@ -313,6 +313,18 @@ exists. See the [config file] documentation for more information. [config file]: config-file.md +### `blur_timeout` + +The number of milliseconds VimFx should wait after an element has been blurred +before checking if you’re inside a text input or not. + +Some sites with fancy text inputs (such as twitter) blur the text input for a +split second and then re-focus it again while typing (for some reason). If you +happen to press a key during that split second, that key might trigger a VimFx +shortcut instead of typing into the text input, which can be quite annoying. To +avoid the problem, VimFx waits a bit before checking if you have left the text +input. + ### `hints_timeout` The number of milliseconds a matched hint marker should stay on screen before diff --git a/extension/lib/defaults.coffee b/extension/lib/defaults.coffee index cd5c8df..c9578c9 100644 --- a/extension/lib/defaults.coffee +++ b/extension/lib/defaults.coffee @@ -165,6 +165,7 @@ advanced_options = 'ignore_ctrl_alt': (Services.appinfo.OS == 'WINNT') 'prevent_autofocus_modes': 'normal' 'config_file_directory': '' + 'blur_timeout': 50 'hints_timeout': 200 'hints_sleep': 15 'smoothScroll.lines.spring-constant': '1000' diff --git a/extension/lib/events-frame.coffee b/extension/lib/events-frame.coffee index 87bd952..5aced6c 100644 --- a/extension/lib/events-frame.coffee +++ b/extension/lib/events-frame.coffee @@ -241,7 +241,9 @@ class FrameEventManager @vim.clearHover() if target == @vim.state.lastHoveredElement - @sendFocusType() + @vim.content.setTimeout((=> + @sendFocusType() + ), prefs.get('blur_timeout')) # If a text input is blurred immediately before the document loses focus, # it most likely means that the user switched tab, for example by pressing diff --git a/extension/lib/events.coffee b/extension/lib/events.coffee index 066f16b..749b110 100644 --- a/extension/lib/events.coffee +++ b/extension/lib/events.coffee @@ -99,7 +99,6 @@ class UIEventManager ) handleFocusRelatedEvent = (event) => - target = event.originalTarget return unless vim = @vimfx.getCurrentVim(@window) if vim.isUIEvent(event) @@ -110,7 +109,11 @@ class UIEventManager vim.enterMode('normal') @listen('focus', handleFocusRelatedEvent) - @listen('blur', handleFocusRelatedEvent) + @listen('blur', (event) => + @window.setTimeout((-> + handleFocusRelatedEvent(event) + ), @vimfx.options.blur_timeout) + ) @listen('click', (event) => target = event.originalTarget -- 2.39.3