Skip to content

Commit

Permalink
Merge pull request #614 from d-i-t-a/feature/prevent-scroll-while-sel…
Browse files Browse the repository at this point in the history
…ection

Added configurable flag for preventing scrolling while text is being selected
  • Loading branch information
aferditamuriqi authored Oct 25, 2023
2 parents 3a760a2 + 8bf6a83 commit ea95e4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@d-i-t-a/reader",
"version": "2.3.18",
"version": "2.4.0",
"description": "A viewer application for EPUB files.",
"repository": "https://github.com/d-i-t-a/R2D2BC",
"license": "Apache-2.0",
Expand Down
15 changes: 15 additions & 0 deletions src/modules/highlight/TextHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ let lastMouseDownY = -1;
export interface TextHighlighterProperties {
selectionMenuItems?: Array<SelectionMenuItem>;
menuPosition?: MenuPosition;
preventScrollOnSelection?: boolean;
}

export interface TextHighlighterConfig extends TextHighlighterProperties {
Expand Down Expand Up @@ -674,6 +675,13 @@ export class TextHighlighter {
async mousedown(ev: MouseEvent) {
lastMouseDownX = ev.clientX;
lastMouseDownY = ev.clientY;
if (this.properties?.preventScrollOnSelection) {
const wrapper = HTMLUtilities.findRequiredElement(
document,
"#iframe-wrapper"
);
wrapper.style.overflow = "hidden";
}
}

async mouseup(ev: MouseEvent) {
Expand Down Expand Up @@ -924,6 +932,13 @@ export class TextHighlighter {
let toolbox = document.getElementById("highlight-toolbox");
if (toolbox) toolbox.style.display = "none";
this.selectionMenuClosed();
if (this.properties?.preventScrollOnSelection) {
const wrapper = HTMLUtilities.findRequiredElement(
document,
"#iframe-wrapper"
);
wrapper.style.overflow = "auto";
}
}

// Use short timeout to let the selection updated to 'finish', otherwise some
Expand Down
1 change: 1 addition & 0 deletions viewer/index_dita.html
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@
console.log("selectionMenuClose");
},
},
preventScrollOnSelection: true,
},
annotations: {
enableComments: true,
Expand Down

0 comments on commit ea95e4f

Please sign in to comment.