Skip to content

Commit 33cb10e

Browse files
committed
fix
1 parent dc3cbb8 commit 33cb10e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/cm/touchSelectionMenu.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class TouchSelectionMenuController {
132132
#isScrolling = false;
133133
#isPointerInteracting = false;
134134
#shiftSelectionSession = null;
135+
#pendingShiftSelectionClick = null;
135136
#menuActive = false;
136137
#menuRequested = false;
137138
#enabled = true;
@@ -176,13 +177,15 @@ class TouchSelectionMenuController {
176177
cancelAnimationFrame(this.#stateSyncRaf);
177178
this.#stateSyncRaf = 0;
178179
this.#shiftSelectionSession = null;
180+
this.#pendingShiftSelectionClick = null;
179181
this.#hideMenu(true);
180182
}
181183

182184
setEnabled(enabled) {
183185
this.#enabled = !!enabled;
184186
if (this.#enabled) return;
185187
this.#shiftSelectionSession = null;
188+
this.#pendingShiftSelectionClick = null;
186189
this.#menuRequested = false;
187190
this.#isPointerInteracting = false;
188191
this.#isScrolling = false;
@@ -254,6 +257,7 @@ class TouchSelectionMenuController {
254257
onSessionChanged() {
255258
if (!this.#enabled) return;
256259
this.#shiftSelectionSession = null;
260+
this.#pendingShiftSelectionClick = null;
257261
this.#menuRequested = false;
258262
this.#isPointerInteracting = false;
259263
this.#isScrolling = false;
@@ -349,6 +353,11 @@ class TouchSelectionMenuController {
349353
selection: EditorSelection.range(session.anchor, head),
350354
userEvent: "select.extend",
351355
});
356+
this.#pendingShiftSelectionClick = {
357+
x: event.clientX,
358+
y: event.clientY,
359+
timeStamp: event.timeStamp,
360+
};
352361
event.preventDefault();
353362
}
354363

@@ -359,6 +368,24 @@ class TouchSelectionMenuController {
359368
return !!this.#isShiftSelectionActive(event);
360369
}
361370

371+
consumePendingShiftSelectionClick(event) {
372+
const pending = this.#pendingShiftSelectionClick;
373+
this.#pendingShiftSelectionClick = null;
374+
if (!pending || !this.#enabled) return false;
375+
if (event.timeStamp - pending.timeStamp > TAP_MAX_DELAY) return false;
376+
if (
377+
Math.hypot(event.clientX - pending.x, event.clientY - pending.y) >
378+
TAP_MAX_DISTANCE
379+
) {
380+
return false;
381+
}
382+
const target = event.target;
383+
if (!(target instanceof Node) || !this.#view.dom.contains(target))
384+
return false;
385+
if (this.#isIgnoredPointerTarget(target)) return false;
386+
return true;
387+
}
388+
362389
#shouldShowMenu() {
363390
if (this.#isScrolling || this.#isPointerInteracting || !this.#view.hasFocus)
364391
return false;

src/lib/editorManager.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ async function EditorManager($header, $body) {
198198
if (!appSettings.value.shiftClickSelection) return false;
199199
return !!event?.shiftKey || quickTools?.$footer?.dataset?.shift != null;
200200
};
201+
const shiftClickSelectionExtension = EditorView.domEventHandlers({
202+
click(event) {
203+
if (!touchSelectionController?.consumePendingShiftSelectionClick(event)) {
204+
return false;
205+
}
206+
event.preventDefault();
207+
return true;
208+
},
209+
});
201210
const touchSelectionUpdateExtension = EditorView.updateListener.of(
202211
(update) => {
203212
if (!touchSelectionController) return;
@@ -755,6 +764,7 @@ async function EditorManager($header, $body) {
755764
commandKeymapExtension: getCommandKeymapExtension(),
756765
themeExtension: themeCompartment.of(oneDark),
757766
pointerCursorVisibilityExtension,
767+
shiftClickSelectionExtension,
758768
touchSelectionUpdateExtension,
759769
searchExtension: search(),
760770
// Ensure read-only can be toggled later via compartment
@@ -1117,6 +1127,7 @@ async function EditorManager($header, $body) {
11171127
// keep compartment in the state to allow dynamic theme changes later
11181128
themeExtension: themeCompartment.of(oneDark),
11191129
pointerCursorVisibilityExtension,
1130+
shiftClickSelectionExtension,
11201131
touchSelectionUpdateExtension,
11211132
searchExtension: search(),
11221133
// Keep dynamic compartments across state swaps

0 commit comments

Comments
 (0)