diff options
| author | Jez Ng | 2012-08-04 22:41:07 -0700 | 
|---|---|---|
| committer | Jez Ng | 2012-08-21 00:25:28 -0700 | 
| commit | 6af96249d408d3a4131bafc5a6b83b46d6b90523 (patch) | |
| tree | 6b6bf9277aa39d7380098ecec9b226b61cd3ed07 /content_scripts/vimium_frontend.coffee | |
| parent | 77e1f226003a696520b364650db20b308e4b71c0 (diff) | |
| download | vimium-6af96249d408d3a4131bafc5a6b83b46d6b90523.tar.bz2 | |
Prototype for tab-through-input-elements feature. Refs #508.
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 35 | 
1 files changed, 25 insertions, 10 deletions
| diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 5b7a7402..1ab938fe 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -301,19 +301,34 @@ extend window,      HUD.showForDuration("Yanked URL", 1000)    focusInput: (count) -> -    results = DomUtils.evaluateXPath(textInputXPath, XPathResult.ORDERED_NODE_ITERATOR_TYPE) +    xpathResult = DomUtils.evaluateXPath(textInputXPath, XPathResult.ORDERED_NODE_ITERATOR_TYPE) +    visibleInputs = +      while (currentInputBox = xpathResult.iterateNext()) +        rect = DomUtils.getVisibleClientRect(currentInputBox) +        continue if rect == null +        { element: currentInputBox, rect: rect } -    lastInputBox -    i = 0 +    return if visibleInputs.length == 0 -    while (i < count) -      currentInputBox = results.iterateNext() -      break unless currentInputBox -      continue if (DomUtils.getVisibleClientRect(currentInputBox) == null) -      lastInputBox = currentInputBox -      i += 1 +    selectedInputIndex = Math.min(count - 1, visibleInputs.length - 1) -    lastInputBox.focus() if lastInputBox +    visibleInputs[selectedInputIndex].element.focus() + +    hintMarkers = (LinkHints.createMarkerFor(el) for el in visibleInputs) + +    for marker, idx in hintMarkers +      marker.innerHTML = "<span>#{idx + 1}</span>" + +    hintMarkerContainingDiv = LinkHints.displayHints(hintMarkers) + +    handlerStack.push keydown: -> +      if event.keyCode == KeyboardUtils.keyCodes.tab +        if ++selectedInputIndex == hintMarkers.length +          selectedInputIndex = 0 +        hintMarkers[selectedInputIndex].clickableItem.focus() +      else +        DomUtils.removeElement hintMarkerContainingDiv +        handlerStack.pop()  #  # Sends everything except i & ESC to the handler in background_page. i & ESC are special because they control | 
