From 7a4ad46f94d2fabdaf0cf04af4eeaef964fc4b62 Mon Sep 17 00:00:00 2001 From: Anton Khodakivskiy Date: Sat, 3 Nov 2012 18:57:39 -0400 Subject: [PATCH] Closes #14. Now if the newly entered character doesn't match any markers then it's ignored - none of the markers will disappear on invalid hints --- extension/packages/commands.coffee | 21 +++++++++++++-------- extension/packages/marker.coffee | 4 ++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/extension/packages/commands.coffee b/extension/packages/commands.coffee index 2b75a93..eae5f8f 100644 --- a/extension/packages/commands.coffee +++ b/extension/packages/commands.coffee @@ -227,14 +227,19 @@ commandsHelp = do (commandGroups) -> # Called in hints mode. Will process the char, update and hide/show markers hintCharHandler = (vim, char) -> - for marker in vim.markers - marker.matchHintChar char - - if marker.isMatched() - vim.cb marker - removeHints vim.window.document - vim.enterNormalMode() - break + # First count how many markers will match with the new character entered + preMatch = vim.markers.reduce ((v, marker) -> v + marker.willMatch char), 0 + + # If prematch is greater than 0, then proceed with matching, else ignore the new char + if preMatch > 0 + for marker in vim.markers + marker.matchHintChar char + + if marker.isMatched() + vim.cb marker + removeHints vim.window.document + vim.enterNormalMode() + break exports.hintCharHandler = hintCharHandler exports.commands = commands diff --git a/extension/packages/marker.coffee b/extension/packages/marker.coffee index 38a2a1c..bee6c6a 100644 --- a/extension/packages/marker.coffee +++ b/extension/packages/marker.coffee @@ -89,6 +89,10 @@ class Marker # then hide the marker. Othersie show it back if @hintChars.search(@enteredHintChars) == 0 then @show() else @hide() + # Checks if the marker will be matched if the next character entered is `char` + willMatch: (char) -> + char == 'backspace' or @hintChars.search(@enteredHintChars + char) == 0 + # Checks if enterd hint chars completely match the hint chars isMatched: -> return @hintChars == @enteredHintChars -- 2.39.3