8000 Make selectParentSyntax able to jump between overlays · codemirror/commands@e209d2f · GitHub
[go: up one dir, main page]

Skip to content

Commit e209d2f

Browse files
committed
Make selectParentSyntax able to jump between overlays
FIX: Make it possible for `selectParentSyntax` to jump out of or into a syntax tree overlay.
1 parent 2a2ff2b commit e209d2f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@codemirror/language": "^6.0.0",
3030
"@codemirror/state": "^6.2.0",
3131
"@codemirror/view": "^6.0.0",
32-
"@lezer/common": "^1.0.0"
32+
"@lezer/common": "^1.1.0"
3333
},
3434
"devDependencies": {
3535
"@codemirror/buildhelper": "^1.0.0",

src/commands.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,15 @@ export const selectLine: StateCommand = ({state, dispatch}) => {
401401
/// syntax tree.
402402
export const selectParentSyntax: StateCommand = ({state, dispatch}) => {
403403
let selection = updateSel(state.selection, range => {
404-
let context = syntaxTree(state).resolveInner(range.head, 1)
405-
while (!((context.from < range.from && context.to >= range.to) ||
406-
(context.to > range.to && context.from <= range.from) ||
407-
!context.parent?.parent))
408-
context = context.parent
409-
return EditorSelection.range(context.to, context.from)
404+
let stack = syntaxTree(state).resolveStack(range.from, 1)
405+
for (let cur: typeof stack | null = stack; cur; cur = cur.next) {
406+
let {node} = cur
407+
if (((node.from < range.from && node.to >= range.to) ||
408+
(node.to > range.to && node.from <= range.from)) &&
409+
node.parent?.parent)
410+
return EditorSelection.range(node.to, node.from)
411+
}
412+
return range
410413
})
411414
dispatch(setSel(state, selection))
412415
return true

0 commit comments

Comments
 (0)
0