[visual] Handle selections adjacent to lists and section headings (#13581)

GitOrigin-RevId: 35b289102110f88587679740eeed575e16f6788b
This commit is contained in:
Alf Eaton
2023-07-17 10:49:53 +00:00
committed by Copybot
parent 1d33231392
commit 52d9ee79a3
3 changed files with 59 additions and 13 deletions
@@ -64,6 +64,28 @@ export function getAncestorStack(
return stack.reverse()
}
export const wrappedNodeOfType = (
state: EditorState,
range: SelectionRange,
type: string | number
): SyntaxNode | null => {
if (range.empty) {
return null
}
const ancestorNode = ancestorNodeOfType(state, range.from, type, 1)
if (
ancestorNode &&
ancestorNode.from === range.from &&
ancestorNode.to === range.to
) {
return ancestorNode
}
return null
}
export const ancestorNodeOfType = (
state: EditorState,
pos: number,