Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions content_scripts/link_hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ const COPY_LINK_TEXT = {
const HOVER_LINK = {
name: "hover",
indicator: "Hover link",
doesScroll: false,
linkActivator(link) {
new HoverMode(link);
new HoverMode(link, HOVER_LINK.doesScroll);
}
};
const FOCUS_LINK = {
Expand Down Expand Up @@ -222,7 +223,10 @@ var LinkHints = {
const action = registryEntry ? registryEntry.options.action : null;
switch (action) {
case "copy-text": mode = COPY_LINK_TEXT; break;
case "hover": mode = HOVER_LINK; break;
case "hover": case "hover-and-scroll":
HOVER_LINK.doesScroll = action !== "hover";
mode = HOVER_LINK;
break;
case "focus": mode = FOCUS_LINK; break;
}

Expand Down Expand Up @@ -1257,10 +1261,13 @@ class WaitForEnter extends Mode {
}

class HoverMode extends Mode {
constructor(link) {
constructor(link, doesScroll) {
super();
super.init({name: "hover-mode", singleton: "hover-mode", exitOnEscape: true});
this.link = link;
if (doesScroll) {
Scroller.selectElement(link);
}
DomUtils.simulateHover(this.link);
this.onExit(() => DomUtils.simulateUnhover(this.link));
}
Expand Down
5 changes: 5 additions & 0 deletions content_scripts/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ const Scroller = {
return (element !== activatedElement) && isScrollableElement(element);
},

// check
selectElement(element) {
activatedElement = element;
},

// Scroll the top, bottom, left and right of element into view. The is used by visual mode to ensure the
// focus remains visible.
scrollIntoView(element) {
Expand Down