From 8e65f74eea14850794ded12a0039a80e825ffa8d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 9 Jan 2015 17:38:57 +0000 Subject: Modes; handle normal mode return values. Up until this point in the development of modes, we've just let the normal mode handlers return whatever they previously would have returned. This allowed keyboard events to continue bubbling down the stack, but didn't matter, because normal mode is the last keyboard handler on the stack. This changes that. Now, normal-mode key handlers return the right value to have the handler stack stop or continue bubbling, as appropriate. --- content_scripts/vimium_frontend.coffee | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index d91bb181..97fbc56f 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -465,17 +465,20 @@ onKeypress = (event, extra) -> # Enter insert mode when the user enables the native find interface. if (keyChar == "f" && KeyboardUtils.isPrimaryModifierKey(event)) enterInsertModeWithoutShowingIndicator() - return true + return handlerStack.stopBubblingAndTrue if (keyChar) if (findMode) handleKeyCharForFindMode(keyChar) DomUtils.suppressEvent(event) + return handlerStack.stopBubblingAndTrue else if (!isInsertMode() && !findMode) if (isPassKey keyChar) return handlerStack.stopBubblingAndTrue if currentCompletionKeys.indexOf(keyChar) != -1 or isValidFirstKey(keyChar) DomUtils.suppressEvent(event) + keyPort.postMessage({ keyChar:keyChar, frameId:frameId }) + return handlerStack.stopBubblingAndTrue keyPort.postMessage({ keyChar:keyChar, frameId:frameId }) @@ -520,37 +523,45 @@ onKeydown = (event, extra) -> exitInsertMode() DomUtils.suppressEvent event KeydownEvents.push event + return handlerStack.stopBubblingAndTrue else if (findMode) if (KeyboardUtils.isEscape(event)) handleEscapeForFindMode() DomUtils.suppressEvent event KeydownEvents.push event + return handlerStack.stopBubblingAndTrue else if (event.keyCode == keyCodes.backspace || event.keyCode == keyCodes.deleteKey) handleDeleteForFindMode() DomUtils.suppressEvent event KeydownEvents.push event + return handlerStack.stopBubblingAndTrue else if (event.keyCode == keyCodes.enter) handleEnterForFindMode() DomUtils.suppressEvent event KeydownEvents.push event + return handlerStack.stopBubblingAndTrue else if (!modifiers) DomUtils.suppressPropagation(event) KeydownEvents.push event + return handlerStack.stopBubblingAndTrue else if (isShowingHelpDialog && KeyboardUtils.isEscape(event)) hideHelpDialog() DomUtils.suppressEvent event KeydownEvents.push event + return handlerStack.stopBubblingAndTrue else if (!isInsertMode() && !findMode) if (keyChar) if (currentCompletionKeys.indexOf(keyChar) != -1 or isValidFirstKey(keyChar)) DomUtils.suppressEvent event KeydownEvents.push event + keyPort.postMessage({ keyChar:keyChar, frameId:frameId }) + return handlerStack.stopBubblingAndTrue keyPort.postMessage({ keyChar:keyChar, frameId:frameId }) @@ -572,12 +583,14 @@ onKeydown = (event, extra) -> isValidFirstKey(KeyboardUtils.getKeyChar(event)))) DomUtils.suppressPropagation(event) KeydownEvents.push event + return handlerStack.stopBubblingAndTrue return true onKeyup = (event) -> - DomUtils.suppressPropagation(event) if KeydownEvents.pop event - return true + return true unless KeydownEvents.pop event + DomUtils.suppressPropagation(event) + handlerStack.stopBubblingAndTrue checkIfEnabledForUrl = -> url = window.location.toString() -- cgit v1.2.3 From ac90db47aa2671cd663cc6a9cdf783dc30a582e9 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 10 Jan 2015 00:00:11 +0000 Subject: Modes; more changes... - Better comments. - Strip unnecessary handlers for leaving post-find mode. - Simplify passKeys. - focusInput now re-bubbles its triggering keydown event. --- content_scripts/vimium_frontend.coffee | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 97fbc56f..a9bf30a3 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -384,8 +384,8 @@ extend window, # shouldn't happen anyway. However, it does no harm to enforce it. singleton: FocusSelector targetMode: targetMode - # For the InsertModeBlocker super-class (we'll always choose InsertMode on click). See comment in - # InsertModeBlocker for an explanation of why this is needed. + # Set the target mode for when/if the active element is clicked. Usually, the target is insert + # mode. See comment in InsertModeBlocker for an explanation of why this is needed. onClickMode: targetMode keydown: (event) => if event.keyCode == KeyboardUtils.keyCodes.tab @@ -397,22 +397,22 @@ extend window, @suppressEvent else unless event.keyCode == KeyboardUtils.keyCodes.shiftKey @exit event - @continueBubbling + # In @exit(), we just pushed a new mode (usually insert mode). Restart bubbling, so that the + # new mode can now see the event too. + @restartBubbling visibleInputs[selectedInputIndex].element.focus() - if visibleInputs.length == 1 - @exit() - else - hints[selectedInputIndex].classList.add 'internalVimiumSelectedInputHint' + return @exit() if visibleInputs.length == 1 + + hints[selectedInputIndex].classList.add 'internalVimiumSelectedInputHint' exit: -> super() DomUtils.removeElement hintContainingDiv if document.activeElement == visibleInputs[selectedInputIndex].element - # The InsertModeBlocker super-class handles the "click" case. + # The InsertModeBlocker super-class handles "click" events, so we should skip it here. unless event?.type == "click" - # In the legacy (and probably common) case, we're entering insert mode here. However, it could be - # some other mode. + # In most cases, we're entering insert mode here. However, it could be some other mode. new @options.targetMode targetElement: document.activeElement @@ -455,7 +455,7 @@ KeydownEvents = # Note that some keys will only register keydown events and not keystroke events, e.g. ESC. # -onKeypress = (event, extra) -> +onKeypress = (event) -> keyChar = "" # Ignore modifier keys by themselves. @@ -484,7 +484,7 @@ onKeypress = (event, extra) -> return true -onKeydown = (event, extra) -> +onKeydown = (event) -> keyChar = "" # handle special keys, and normal input keys with modifiers being pressed. don't handle shiftKey alone (to @@ -789,6 +789,7 @@ class FindMode extends InsertModeBlocker super() handleEscapeForFindMode() if event?.type == "keydown" and KeyboardUtils.isEscape event handleEscapeForFindMode() if event?.type == "click" + # If event?.type == "click", then the InsertModeBlocker super-class will be dropping us into insert mode. new PostFindMode findModeAnchorNode unless event?.type == "click" performFindInPlace = -> -- cgit v1.2.3 From fdcdd0113049042c94b2b56a6b716e2da58b860e Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 10 Jan 2015 08:25:02 +0000 Subject: Modes; instrument for debugging... - Set Mode.debug to true to see mode activation/deactivation on the console. - Use Mode.log() to see a list of currently-active modes. - Use handlerStack.debugOn() to enable debugging of the handler stack. --- content_scripts/vimium_frontend.coffee | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index a9bf30a3..1406b1e7 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -396,10 +396,16 @@ extend window, visibleInputs[selectedInputIndex].element.focus() @suppressEvent else unless event.keyCode == KeyboardUtils.keyCodes.shiftKey - @exit event - # In @exit(), we just pushed a new mode (usually insert mode). Restart bubbling, so that the - # new mode can now see the event too. - @restartBubbling + mode = @exit event + if mode + # In @exit(), we just pushed a new mode (usually insert mode). Restart bubbling, so that the + # new mode can now see the event too. + # Exception: If the new mode exits on Escape, and this key event is Escape, then rebubbling the + # event will just cause the mode to exit immediately. So we suppress Escapes. + if mode.options.exitOnEscape and KeyboardUtils.isEscape event + @suppressEvent + else + @restartBubbling visibleInputs[selectedInputIndex].element.focus() return @exit() if visibleInputs.length == 1 -- cgit v1.2.3 From 80ad0bc3087a3bf00d61bdd6c9cf48e971e22480 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 10 Jan 2015 18:52:24 +0000 Subject: Modes; re-architect key suppression and passkeys. --- content_scripts/vimium_frontend.coffee | 2 ++ 1 file changed, 2 insertions(+) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 1406b1e7..0da59f03 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -462,6 +462,7 @@ KeydownEvents = # onKeypress = (event) -> + return true if event.vimium_suppress_normal_mode keyChar = "" # Ignore modifier keys by themselves. @@ -491,6 +492,7 @@ onKeypress = (event) -> return true onKeydown = (event) -> + return true if event.vimium_suppress_normal_mode keyChar = "" # handle special keys, and normal input keys with modifiers being pressed. don't handle shiftKey alone (to -- cgit v1.2.3