From 859e79235db87f15c1b8695f4f1384a6d7849903 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 12 Sep 2016 18:15:30 +0200 Subject: [PATCH] Correctly suppress keys between `/` and find bar focus Fixes #786. --- extension/lib/commands.coffee | 18 +++++++++++++----- extension/lib/modes.coffee | 25 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index a160537..6a89cf8 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -782,24 +782,27 @@ findStorage = { } helper_find_from_top_of_viewport = (vim, direction, callback) -> - return if findStorage.busy if vim.options.find_from_top_of_viewport - findStorage.busy = true vim._run('find_from_top_of_viewport', {direction}, -> - findStorage.busy = false callback() ) else callback() helper_find = ({highlight, linksOnly = false}, {vim}) -> + if findStorage.busy + # Make sure to enter find mode here, since that’s where `findStorage.busy` + # is reset to `false` again. Otherwise we can get stuck in the “busy” state. + vim._enterMode('find') + return + helpSearchInput = help.getSearchInput(vim.window) if helpSearchInput helpSearchInput.select() return - # In case `helper_find_from_top_of_viewport` is slow, make sure that keys - # pressed before the find bar input is focsued doesn’t trigger commands. + # Important: Enter Find mode immediately. See `onInput` for Find mode. + findStorage.busy = true vim._enterMode('find') helper_mark_last_scroll_position(vim) @@ -824,11 +827,15 @@ commands.find_highlight_all = helper_find.bind(null, {highlight: true}) commands.find_links_only = helper_find.bind(null, {linksOnly: true}) helper_find_again = (direction, {vim}) -> + return if findStorage.busy + findBar = vim.window.gBrowser.getFindBar() if findStorage.lastSearchString.length == 0 vim.notify(translate('notification.find_again.none')) return + findStorage.busy = true + helper_mark_last_scroll_position(vim) helper_find_from_top_of_viewport(vim, direction, -> findBar._findField.value = findStorage.lastSearchString @@ -843,6 +850,7 @@ helper_find_again = (direction, {vim}) -> findBar.onFindResult(data) message = findBar._findStatusDesc.textContent vim.notify(message) if message + findStorage.busy = false findBar.onFindAgainCommand(not direction) ) diff --git a/extension/lib/modes.coffee b/extension/lib/modes.coffee index cd82e99..12be57f 100644 --- a/extension/lib/modes.coffee +++ b/extension/lib/modes.coffee @@ -331,13 +331,28 @@ mode('find', { onLeave: ({vim}) -> findBar = vim.window.gBrowser.getFindBar() findStorage.lastSearchString = findBar._findField.value + findStorage.busy = false onInput: (args, match) -> - args.findBar = args.vim.window.gBrowser.getFindBar() - if match.type == 'full' - match.command.run(args) - return true - return false + {vim} = args + switch + when match.type == 'full' + args.findBar = args.vim.window.gBrowser.getFindBar() + match.command.run(args) + return true + when vim.focusType != 'findbar' + # If we’re in Find mode but the find bar input hasn’t been focused yet, + # suppress all input, because we don’t want to trigger Firefox commands, + # such as `/` (which opens the Quick Find bar). This happens when + # `helper_find_from_top_of_viewport` is slow, or when _Firefox_ is slow, + # for example to due to heavy page loading. The following URL is a good + # stress test: + findStorage.busy = true + return true + else + # At this point we know for sure that the find bar is not busy anymore. + findStorage.busy = false + return false }, { exit: ({vim, findBar}) -> -- 2.39.3