From 0d630e97b7c31995abbe07e4a3cae41bf219c551 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 29 Aug 2016 22:11:41 +0200 Subject: [PATCH] Fix missing hint markers when re-entering Hints mode quickly 1. Enter Hints mode. 2. Press `` to exit it. 3. Press `f` to re-enter Hints mode within `hints_timeout` milliseconds. This used to result in re-entering Hints mode as expected, but with no hint markers on screen because of a timeout from the last Hints mode session that removed the hints container. Removing the hints container is done by ID for robustness, so it doesn't help that the hints container actually is a new DOM element at that time. This commit fixes the above problem, and makes the logic more robust. In `onLeave` for Hints mode, it makes sense to always try to remove the Hints container, so that it may not be accidentally be left on screen. However, it does not make sense to do so after a timeout, which was previously the case. Now, it is done _immediately_ instead. The only case where he timeout is wanted, is when a hint marker just has been matched. This commit also adds a check in that timeout callback that Hints mode hasn't been re-entered before removing the hints container. --- extension/lib/modes.coffee | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/extension/lib/modes.coffee b/extension/lib/modes.coffee index 08810d3..145d7cd 100644 --- a/extension/lib/modes.coffee +++ b/extension/lib/modes.coffee @@ -211,11 +211,7 @@ mode('hints', { ) onLeave: ({vim, storage}) -> - {markerContainer} = storage - vim.window.setTimeout( - (-> markerContainer.remove()), - vim.options.hints_timeout - ) + storage.markerContainer?.remove() storage.clearInterval?() for key of storage storage[key] = null @@ -227,18 +223,31 @@ mode('hints', { if match.type == 'full' match.command.run(args) + else if match.unmodifiedKey in vim.options.hint_chars matchedMarkers = markerContainer.matchHintChar(match.unmodifiedKey) + if matchedMarkers.length > 0 again = callback(matchedMarkers[0], storage.count, match.keyStr) storage.count -= 1 + if again vim.window.setTimeout((-> marker.markMatched(false) for marker in matchedMarkers return ), vim.options.hints_timeout) markerContainer.reset() + else + vim.window.setTimeout((-> + # Don’t remove the marker container if we have re-entered Hints mode + # before the timeout has passed. + markerContainer.remove() unless vim.mode == 'hints' + ), vim.options.hints_timeout) + + # Prevent `onLeave` from removing the markers immediately. + storage.markerContainer = null + # The callback might have entered another mode. Only go back to Normal # mode if we’re still in Hints mode. vim._enterMode('normal') if vim.mode == 'hints' @@ -246,10 +255,7 @@ mode('hints', { return true }, { - exit: ({vim, storage}) -> - # The hints are removed automatically when leaving the mode, but after a - # timeout. When aborting the mode we should remove the hints immediately. - storage.markerContainer.remove() + exit: ({vim}) -> vim._enterMode('normal') rotate_markers_forward: ({storage}) -> -- 2.39.3