Skip to content

Commit

Permalink
Link-hint mode command options (incl. hover, focus)
Browse files Browse the repository at this point in the history
This adds:

    map X LinkHints.activateMode action=hover
    map X LinkHints.activateMode action=focus
    map X LinkHints.activateMode action=copy-text

For "hover", `<Escape>` generates the `mouseout` event.
  • Loading branch information
smblott-github committed Aug 17, 2018
1 parent a4a9c4e commit d128370
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
35 changes: 33 additions & 2 deletions content_scripts/link_hints.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,28 @@ DOWNLOAD_LINK_URL =
name: "download"
indicator: "Download link URL"
clickModifiers: altKey: true, ctrlKey: false, metaKey: false
COPY_LINK_TEXT =
name: "copy-link-text"
indicator: "Copy link text"
linkActivator: (link) ->
text = link.textContent
if 0 < text.length
HUD.copyToClipboard text
text = text[0..25] + "...." if 28 < text.length
HUD.showForDuration "Yanked #{text}", 2000
else
HUD.showForDuration "No text to yank.", 2000
HOVER_LINK =
name: "hover"
indicator: "Hover link"
linkActivator: (link) -> new HoverMode link
FOCUS_LINK =
name: "focus"
indicator: "Focus link"
linkActivator: (link) -> link.focus()

availableModes = [OPEN_IN_CURRENT_TAB, OPEN_IN_NEW_BG_TAB, OPEN_IN_NEW_FG_TAB, OPEN_WITH_QUEUE, COPY_LINK_URL,
OPEN_INCOGNITO, DOWNLOAD_LINK_URL]
OPEN_INCOGNITO, DOWNLOAD_LINK_URL, COPY_LINK_TEXT, HOVER_LINK, FOCUS_LINK]

HintCoordinator =
onExit: []
Expand Down Expand Up @@ -124,8 +143,14 @@ HintCoordinator =
@linkHintsMode = @localHints = null

LinkHints =
activateMode: (count = 1, {mode}) ->
activateMode: (count = 1, {mode, registryEntry}) ->
mode ?= OPEN_IN_CURRENT_TAB
# Handle modes which are only accessible via command options.
switch registryEntry?.options.action
when "copy-text" then mode = COPY_LINK_TEXT
when "hover" then mode = HOVER_LINK
when "focus" then mode = FOCUS_LINK
#
if 0 < count or mode is OPEN_WITH_QUEUE
HintCoordinator.prepareToActivateMode mode, (isSuccess) ->
if isSuccess
Expand Down Expand Up @@ -889,6 +914,12 @@ class WaitForEnter extends Mode
@exit()
callback false # false -> isSuccess.

class HoverMode extends Mode
constructor: (@link) ->
DomUtils.simulateHover @link
super name: "hover-mode", singleton: "hover-mode", exitOnEscape: true
@onExit => DomUtils.simulateUnhover @link

root = exports ? (window.root ?= {})
root.LinkHints = LinkHints
root.HintCoordinator = HintCoordinator
Expand Down
6 changes: 6 additions & 0 deletions lib/dom_utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ DomUtils =

return

simulateHover: (element, modifiers = {}) ->
@simulateMouseEvent "mouseover", element, modifiers

simulateUnhover: (element, modifiers = {}) ->
@simulateMouseEvent "mouseout", element, modifiers

addFlashRect: (rect) ->
flashEl = @createElement "div"
flashEl.classList.add "vimiumReset"
Expand Down

0 comments on commit d128370

Please sign in to comment.