Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action=hover-and-scroll to LinkHints #4016

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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