|
1 | 1 | import sidebarApps from "sidebarApps"; |
2 | 2 | import { indentUnit } from "@codemirror/language"; |
3 | 3 | import { search } from "@codemirror/search"; |
4 | | -import { Compartment, EditorState, Prec, StateEffect } from "@codemirror/state"; |
| 4 | +import { |
| 5 | + Compartment, |
| 6 | + EditorSelection, |
| 7 | + EditorState, |
| 8 | + Prec, |
| 9 | + StateEffect, |
| 10 | +} from "@codemirror/state"; |
5 | 11 | import { oneDark } from "@codemirror/theme-one-dark"; |
6 | 12 | import { |
7 | 13 | EditorView, |
@@ -172,6 +178,36 @@ async function EditorManager($header, $body) { |
172 | 178 | }, |
173 | 179 | ); |
174 | 180 |
|
| 181 | + let shiftTapSelectionFix; |
| 182 | + { |
| 183 | + const pointerIdMap = new Map(); |
| 184 | + shiftTapSelectionFix = EditorView.domEventHandlers({ |
| 185 | + pointerup(event, view) { |
| 186 | + if (!(event.isTrusted && event.isPrimary)) return; |
| 187 | + if (!event.shiftKey && quickTools.$footer.dataset.shift == null) return; |
| 188 | + const { pointerId } = event; |
| 189 | + const tid = setTimeout(() => pointerIdMap.delete(pointerId), 1001); |
| 190 | + pointerIdMap.set(pointerId, [view.state.selection.main.anchor, tid]); |
| 191 | + }, |
| 192 | + click(event, view) { |
| 193 | + const { pointerId } = event; |
| 194 | + if (!pointerIdMap.has(pointerId)) return false; |
| 195 | + const [anchor, tid] = pointerIdMap.get(pointerId); |
| 196 | + clearTimeout(tid); |
| 197 | + pointerIdMap.delete(pointerId); |
| 198 | + view.dispatch({ |
| 199 | + selection: EditorSelection.range( |
| 200 | + anchor, |
| 201 | + view.state.selection.main.anchor, |
| 202 | + ), |
| 203 | + userEvent: "select.extend", |
| 204 | + }); |
| 205 | + event.preventDefault(); |
| 206 | + return true; |
| 207 | + }, |
| 208 | + }); |
| 209 | + } |
| 210 | + |
175 | 211 | const touchSelectionUpdateExtension = EditorView.updateListener.of( |
176 | 212 | (update) => { |
177 | 213 | if (!touchSelectionController) return; |
@@ -725,6 +761,7 @@ async function EditorManager($header, $body) { |
725 | 761 | fixedHeightTheme, |
726 | 762 | scrollPastEnd(), |
727 | 763 | pointerCursorVisibilityExtension, |
| 764 | + shiftTapSelectionFix, |
728 | 765 | touchSelectionUpdateExtension, |
729 | 766 | search(), |
730 | 767 | // Ensure read-only can be toggled later via compartment |
@@ -1088,6 +1125,7 @@ async function EditorManager($header, $body) { |
1088 | 1125 | fixedHeightTheme, |
1089 | 1126 | scrollPastEnd(), |
1090 | 1127 | pointerCursorVisibilityExtension, |
| 1128 | + shiftTapSelectionFix, |
1091 | 1129 | touchSelectionUpdateExtension, |
1092 | 1130 | search(), |
1093 | 1131 | // Keep dynamic compartments across state swaps |
|
0 commit comments