Skip to content

Commit 810f80f

Browse files
Include hidden syntax in drag selections starting at content boundary
When a drag starts at the visual left edge of hidden syntax (e.g. the first visible character of a heading), the anchor was staying at contentStart because the reveal check bailed out. Pass ignoreReveal for drag anchors so they snap to before the hidden prefix.
1 parent cf9ed24 commit 810f80f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

app/src/features/editor/extensions/markdown-decorations/snap-cursor.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ const ATX_HEADING_NAMES = new Set([
3131
export function getSnappedCursorPosition(
3232
state: EditorState,
3333
pos: number,
34+
/** Skip the "is syntax already revealed?" check. Used for drag-
35+
* selection anchors where the anchor was placed while syntax was
36+
* still hidden but the cursor has since moved onto the line. */
37+
ignoreReveal = false,
3438
): number | null {
3539
const tree = syntaxTree(state);
3640
const node = tree.resolveInner(pos, 1);
37-
const cursorLines = getCursorLineRanges(state);
38-
const cursorRanges = getCursorRanges(state);
41+
const cursorLines = ignoreReveal ? [] : getCursorLineRanges(state);
42+
const cursorRanges = ignoreReveal ? [] : getCursorRanges(state);
3943

4044
for (let n: SyntaxNode | null = node; n; n = n.parent) {
4145
const snap = snapNodeSyntax(state, n, pos, cursorLines, cursorRanges);
@@ -54,8 +58,9 @@ export function getSnappedPointerSelection(
5458
let changed = false;
5559
const ranges = ("ranges" in selection ? selection.ranges : [selection]).map(
5660
(range) => {
61+
const isDrag = range.anchor !== range.head;
5762
const anchor =
58-
getSnappedCursorPosition(state, range.anchor) ?? range.anchor;
63+
getSnappedCursorPosition(state, range.anchor, isDrag) ?? range.anchor;
5964
const head = getSnappedCursorPosition(state, range.head) ?? range.head;
6065

6166
if (anchor !== range.anchor || head !== range.head) {

0 commit comments

Comments
 (0)