Skip to content

Commit

Permalink
[#66130] check if editor can be scrolled
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Sep 25, 2024
1 parent 131e858 commit 6dd6f41
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/extensions/syncDualPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export function handlePreviewClickToScroll(/** @type {{ target: HTMLElement }} *

const editorScrollOffset = targetRect.top;
const top = lineBlock.top - editorScrollOffset + previewRect.top + previewTopPadding;
const direction = Math.sign(editor.scrollTop - top);
const canScroll =
!(direction === 1 && editor.scrollTop === 0) && !(direction === -1 && editor.scrollTop + editor.clientHeight >= editor.scrollHeight);
editor.scrollTo({
top,
behavior: "smooth",
Expand All @@ -89,11 +92,11 @@ export function handlePreviewClickToScroll(/** @type {{ target: HTMLElement }} *
selection: EditorSelection.create([EditorSelection.range(line.to, line.to)]),
});
window.myst_editor.main_editor.focus();
if (top >= 0) {
if (canScroll) {
editor.removeEventListener("scrollend", setCursor);
}
}
if (top >= 0) {
if (canScroll) {
editor.addEventListener("scrollend", setCursor);
} else {
setCursor();
Expand Down

0 comments on commit 6dd6f41

Please sign in to comment.