Skip to content

Commit c09dc06

Browse files
committed
fix
1 parent c8e14fe commit c09dc06

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/cm/touchSelectionMenu.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class TouchSelectionMenuController {
149149
#selectionActive = false;
150150
#menuActive = false;
151151
#enabled = true;
152+
#touchListenersAttached = false;
153+
#touchMovePassive = true;
152154
#handlingMenuAction = false;
153155
#pendingPointerTriggered = false;
154156
#pendingSelectionChanged = false;
@@ -494,7 +496,7 @@ class TouchSelectionMenuController {
494496
longPressFired: false,
495497
};
496498

497-
this.#addTouchListeners();
499+
this.#addTouchListeners({ passiveMove: true });
498500
this.#clearLongPress();
499501
this.#longPressTimer = setTimeout(() => {
500502
if (!this.#touchSession || this.#touchSession.moved) return;
@@ -627,18 +629,32 @@ class TouchSelectionMenuController {
627629
this.#showCursorHandle();
628630
};
629631

630-
#addTouchListeners() {
632+
#addTouchListeners({ passiveMove = true } = {}) {
633+
if (
634+
this.#touchListenersAttached &&
635+
this.#touchMovePassive === passiveMove
636+
) {
637+
return;
638+
}
639+
if (this.#touchListenersAttached) {
640+
this.#removeTouchListeners();
641+
}
642+
this.#touchMovePassive = passiveMove;
631643
document.addEventListener("touchmove", this.#onTouchMove, {
632-
passive: false,
644+
passive: passiveMove,
633645
});
634646
document.addEventListener("touchend", this.#onTouchEnd, {
635647
passive: false,
636648
});
649+
this.#touchListenersAttached = true;
637650
}
638651

639652
#removeTouchListeners() {
653+
if (!this.#touchListenersAttached) return;
640654
document.removeEventListener("touchmove", this.#onTouchMove);
641655
document.removeEventListener("touchend", this.#onTouchEnd);
656+
this.#touchListenersAttached = false;
657+
this.#touchMovePassive = true;
642658
}
643659

644660
#clearLongPress() {
@@ -1047,7 +1063,7 @@ class TouchSelectionMenuController {
10471063
};
10481064
this.#pointer.x = x;
10491065
this.#pointer.y = y;
1050-
this.#addTouchListeners();
1066+
this.#addTouchListeners({ passiveMove: false });
10511067
}
10521068

10531069
#dragTo(x, y) {

src/lib/editorManager.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ async function EditorManager($header, $body) {
233233
update.selectionSet ||
234234
update.docChanged ||
235235
update.geometryChanged ||
236-
update.viewportChanged ||
237236
pointerTriggered
238237
) {
239238
cancelAnimationFrame(touchSelectionSyncRaf);
@@ -1771,13 +1770,21 @@ async function EditorManager($header, $body) {
17711770
let checkTimeout = null;
17721771
let autosaveTimeout;
17731772
let scrollTimeout;
1773+
let scrollSyncRaf = 0;
17741774
const scroller = editor.scrollDOM;
17751775

1776-
function handleEditorScroll() {
1777-
if (!scroller) return;
1776+
function syncScrollUi() {
1777+
scrollSyncRaf = 0;
17781778
onscrolltop();
17791779
onscrollleft();
17801780
touchSelectionController?.onScroll();
1781+
}
1782+
1783+
function handleEditorScroll() {
1784+
if (!scroller) return;
1785+
if (!scrollSyncRaf) {
1786+
scrollSyncRaf = requestAnimationFrame(syncScrollUi);
1787+
}
17811788
clearTimeout(scrollTimeout);
17821789
isScrolling = true;
17831790
scrollTimeout = setTimeout(() => {

0 commit comments

Comments
 (0)