diff options
| author | Stephen Blott | 2015-04-18 12:49:32 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-04-18 13:01:01 +0100 | 
| commit | a0959294e5724137ee08ad8c6b935e1c3284e06e (patch) | |
| tree | 10591e42eb7bb52067f29200758df4b611ca5f68 /content_scripts | |
| parent | 870bd7831bdddf26d95017e390329b8f2bd3777e (diff) | |
| download | vimium-a0959294e5724137ee08ad8c6b935e1c3284e06e.tar.bz2 | |
Mode indicator: more fix for link hints.
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/link_hints.coffee | 50 | ||||
| -rw-r--r-- | content_scripts/mode.coffee | 12 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 2 | 
3 files changed, 33 insertions, 31 deletions
| diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index f1c7c43c..73af6a06 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -54,18 +54,19 @@ LinkHints =        return      @isActive = true +    hintMarkers = (@createMarkerFor(el) for el in @getVisibleClickableElements()) +    @getMarkerMatcher().fillInMarkers(hintMarkers) +      @hintMode = new Mode        name: "hint/#{mode.name}"        indicator: false        passInitialKeyupEvents: true -      keydown: @onKeyDownInMode.bind(this, hintMarkers), -      # trap all key events +      keydown: @onKeyDownInMode.bind this, hintMarkers +      # Trap all other key events.        keypress: -> false        keyup: -> false -    @setOpenLinkMode(mode) -    hintMarkers = (@createMarkerFor(el) for el in @getVisibleClickableElements()) -    @getMarkerMatcher().fillInMarkers(hintMarkers) +    @setOpenLinkMode mode      # Note(philc): Append these markers as top level children instead of as child nodes to the link itself,      # because some clickable elements cannot contain children, e.g. submit buttons. This has the caveat @@ -76,39 +77,33 @@ LinkHints =    setOpenLinkMode: (@mode) ->      if @mode is OPEN_IN_NEW_BG_TAB or @mode is OPEN_IN_NEW_FG_TAB or @mode is OPEN_WITH_QUEUE        if @mode is OPEN_IN_NEW_BG_TAB -        HUD.show("Open link in new tab") +        @hintMode.setIndicator "Open link in new tab"        else if @mode is OPEN_IN_NEW_FG_TAB -        HUD.show("Open link in new tab and switch to it") +        @hintMode.setIndicator "Open link in new tab and switch to it"        else -        HUD.show("Open multiple links in a new tab") +        @hintMode.setIndicator "Open multiple links in a new tab"        @linkActivator = (link) ->          # When "clicking" on a link, dispatch the event with the appropriate meta key (CMD on Mac, CTRL on          # windows) to open it in a new tab if necessary. -        DomUtils.simulateClick(link, { -          shiftKey: @mode is OPEN_IN_NEW_FG_TAB, -          metaKey: KeyboardUtils.platform == "Mac", -          ctrlKey: KeyboardUtils.platform != "Mac", -          altKey: false}) +        DomUtils.simulateClick link, +          shiftKey: @mode is OPEN_IN_NEW_FG_TAB +          metaKey: KeyboardUtils.platform == "Mac" +          ctrlKey: KeyboardUtils.platform != "Mac" +          altKey: false      else if @mode is COPY_LINK_URL -      HUD.show("Copy link URL to Clipboard") +      @hintMode.setIndicator "Copy link URL to Clipboard"        @linkActivator = (link) -> -        chrome.runtime.sendMessage({handler: "copyToClipboard", data: link.href}) +        chrome.runtime.sendMessage handler: "copyToClipboard", data: link.href      else if @mode is OPEN_INCOGNITO -      HUD.show("Open link in incognito window") - +      @hintMode.setIndicator "Open link in incognito window"        @linkActivator = (link) -> -        chrome.runtime.sendMessage( -          handler: 'openUrlInIncognito' -          url: link.href) +        chrome.runtime.sendMessage handler: 'openUrlInIncognito', url: link.href      else if @mode is DOWNLOAD_LINK_URL -      HUD.show("Download link URL") +      @hintMode.setIndicator "Download link URL"        @linkActivator = (link) -> -        DomUtils.simulateClick(link, { -          altKey: true, -          ctrlKey: false, -          metaKey: false }) +        DomUtils.simulateClick link, altKey: true, ctrlKey: false, metaKey: false      else # OPEN_IN_CURRENT_TAB -      HUD.show("Open link in current tab") +      @hintMode.setIndicator "Open link in current tab"        @linkActivator = (link) -> DomUtils.simulateClick.bind(DomUtils, link)()    # @@ -275,8 +270,8 @@ LinkHints =        handlerStack.push          keyup: (event) =>            if event.keyCode == keyCode -            @setOpenLinkMode previousMode if @isActive              handlerStack.remove() +            @setOpenLinkMode previousMode if @isActive            true      # TODO(philc): Ignore keys that have modifiers. @@ -346,7 +341,6 @@ LinkHints =          DomUtils.removeElement LinkHints.hintMarkerContainingDiv        LinkHints.hintMarkerContainingDiv = null        @hintMode.exit() -      HUD.hide()        @isActive = false      # we invoke the deactivate() function directly instead of using setTimeout(callback, 0) so that diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index ad66f2d7..a2ac5b8c 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -55,6 +55,7 @@ class Mode          # Update the mode indicator.  Setting @options.indicator to a string shows a mode indicator in the          # HUD.  Setting @options.indicator to 'false' forces no mode indicator.  If @options.indicator is          # undefined, then the request propagates to the next mode. +        # The active indicator can also be changed with @setIndicator().          if @options.indicator?            if @options.indicator then HUD?.show @options.indicator else HUD?.hide true, false            @stopBubblingAndTrue @@ -130,10 +131,17 @@ class Mode            if KeyboardUtils.isPrintable event then @stopBubblingAndFalse else @stopBubblingAndTrue      Mode.modes.push @ -    handlerStack.bubbleEvent 'indicator' +    @setIndicator()      @logModes()      # End of Mode constructor. +  setIndicator: (indicator = @options.indicator) -> +    @options.indicator = indicator +    Mode.setIndicator() + +  @setIndicator: -> +    handlerStack.bubbleEvent "indicator" +    push: (handlers) ->      handlers._name ||= "mode-#{@id}"      @handlers.push handlerStack.push handlers @@ -152,7 +160,7 @@ class Mode        handlerStack.remove handlerId for handlerId in @handlers        Mode.modes = Mode.modes.filter (mode) => mode != @        @modeIsActive = false -      handlerStack.bubbleEvent 'indicator' +      @setIndicator()    deactivateSingleton: (singleton) ->      Mode.singletons?[Utils.getIdentity singleton]?.exit() diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 2daec176..50f97181 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -1103,7 +1103,7 @@ HUD =      clearInterval(HUD._tweenId)      if immediate        HUD.displayElement().style.display = "none" unless updateIndicator -      handlerStack.bubbleEvent "indicator" if updateIndicator +      Mode.setIndicator() if updateIndicator      else        HUD._tweenId = Tween.fade HUD.displayElement(), 0, 150, -> HUD.hide true, updateIndicator | 
