aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/vimium_frontend.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-01-14 07:57:09 +0000
committerStephen Blott2015-01-14 09:46:00 +0000
commit9b0a48955c61c262cc4428b2360938d4b54d2d41 (patch)
tree3abda5d154e96ad019eb9aa67ff59a362775fa23 /content_scripts/vimium_frontend.coffee
parent7e1c3475ed9241a5e1fbf78b8134e6ed669ea906 (diff)
downloadvimium-9b0a48955c61c262cc4428b2360938d4b54d2d41.tar.bz2
Modes; substantial reworking of insert mode (and friends).
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
-rw-r--r--content_scripts/vimium_frontend.coffee40
1 files changed, 8 insertions, 32 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index f2e0cb2a..00d90e81 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -6,6 +6,7 @@
#
passKeysMode = null
+insertMode = null
targetElement = null
findMode = false
findModeQuery = { rawQuery: "", matchCount: 0 }
@@ -127,8 +128,7 @@ initializePreDomReady = ->
new NormalMode()
Scroller.init settings
passKeysMode = new PassKeysMode()
- new InsertMode
- permanentInsertMode: true
+ insertMode = new InsertMode()
checkIfEnabledForUrl()
@@ -337,11 +337,10 @@ extend window,
enterVisualMode: =>
new VisualMode()
- focusInput: (count, targetMode = InsertMode) ->
+ focusInput: (count) ->
# Focus the first input element on the page, and create overlays to highlight all the input elements, with
# the currently-focused element highlighted specially. Tabbing will shift focus to the next input element.
# Pressing any other key will remove the overlays and the special tab behavior.
- # targetMode is the mode we want to enter.
resultSet = DomUtils.evaluateXPath(textInputXPath, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE)
visibleInputs =
for i in [0...resultSet.snapshotLength] by 1
@@ -375,13 +374,7 @@ extend window,
super
name: "focus-selector"
badge: "?"
- # Be a singleton. It doesn't make any sense to have two instances active at the same time; and that
- # shouldn't happen anyway. However, it does no harm to enforce it.
- singleton: FocusSelector
- targetMode: targetMode
- # 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
+ exitOnClick: true
keydown: (event) =>
if event.keyCode == KeyboardUtils.keyCodes.tab
hints[selectedInputIndex].classList.remove 'internalVimiumSelectedInputHint'
@@ -391,16 +384,8 @@ extend window,
visibleInputs[selectedInputIndex].element.focus()
@suppressEvent
else unless event.keyCode == KeyboardUtils.keyCodes.shiftKey
- 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
+ @exit()
+ @continueBubbling
visibleInputs[selectedInputIndex].element.focus()
return @exit() if visibleInputs.length == 1
@@ -408,14 +393,8 @@ extend window,
hints[selectedInputIndex].classList.add 'internalVimiumSelectedInputHint'
exit: ->
- super()
DomUtils.removeElement hintContainingDiv
- if document.activeElement == visibleInputs[selectedInputIndex].element
- # The InsertModeBlocker super-class handles "click" events, so we should skip it here.
- unless event?.type == "click"
- # In most cases, we're entering insert mode here. However, it could be some other mode.
- new @options.targetMode
- targetElement: document.activeElement
+ super()
# Decide whether this keyChar should be passed to the underlying page.
# Keystrokes are *never* considered passKeys if the keyQueue is not empty. So, for example, if 't' is a
@@ -823,10 +802,7 @@ executeFind = (query, options) ->
HUD.hide(true)
# ignore the selectionchange event generated by find()
document.removeEventListener("selectionchange",restoreDefaultSelectionHighlight, true)
- handlerId = handlerStack.push
- focus: -> handlerStack.stopBubblingAndTrue
- result = window.find(query, options.caseSensitive, options.backwards, true, false, true, false)
- handlerStack.remove
+ result = window.find(query, options.caseSensitive, options.backwards, true, false, true, false)
setTimeout(
-> document.addEventListener("selectionchange", restoreDefaultSelectionHighlight, true)
0)