Skip to content

Commit e6a529e

Browse files
committed
FF: Simulate default action for clicking links with link hints
1 parent 4099067 commit e6a529e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

background_scripts/main.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ TabOperations =
106106
index: request.tab.index + 1
107107
active: true
108108
windowId: request.tab.windowId
109+
tabConfig.active = request.active if request.active?
109110
# Firefox does not support "about:newtab" in chrome.tabs.create.
110111
delete tabConfig["url"] if tabConfig["url"] == Settings.defaults.newTabUrl
111112
chrome.tabs.create tabConfig, (tab) ->

content_scripts/link_hints.coffee

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# The "name" property below is a short-form name to appear in the link-hints mode's name. It's for debug only.
1212
#
1313
isMac = KeyboardUtils.platform == "Mac"
14+
simulateClickDefaultAction = true
1415
OPEN_IN_CURRENT_TAB =
1516
name: "curr-tab"
1617
indicator: "Open link in current tab"
@@ -384,7 +385,16 @@ class LinkHintsMode
384385
window.focus()
385386
DomUtils.simulateSelect clickEl
386387
else
387-
clickActivator = (modifiers) -> (link) -> DomUtils.simulateClick link, modifiers
388+
clickActivator = (modifiers) -> (link) ->
389+
defaultActionsTriggered = DomUtils.simulateClick link, modifiers
390+
if simulateClickDefaultAction and
391+
defaultActionsTriggered[3] and link.tagName?.toLowerCase() == "a" and
392+
modifiers? and modifiers.metaKey == isMac and modifiers.ctrlKey == not isMac
393+
# We've clicked a link that *should* open in a new tab. If simulateClickDefaultAction is true,
394+
# we assume the popup-blocker is active, and simulate opening the new tab ourselves.
395+
chrome.runtime.sendMessage {handler: "openUrlInNewTab", url: link.href, active:
396+
modifiers.shiftKey == true}
397+
388398
linkActivator = @mode.linkActivator ? clickActivator @mode.clickModifiers
389399
# TODO: Are there any other input elements which should not receive focus?
390400
if clickEl.nodeName.toLowerCase() in ["input", "select"] and clickEl.type not in ["button", "submit"]

0 commit comments

Comments
 (0)