1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-10-06 22:17:10 +02:00
Files
joplin/packages/editor/ProseMirror/utils/selectFirstInstanceOfNode.ts

21 lines
483 B
TypeScript

import { NodeSelection } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
const selectFirstInstanceOfNode = (view: EditorView, nodeName: string) => {
const state = view.state;
let index = -1;
state.doc.descendants((node, pos) => {
if (node.type.name === nodeName) {
index = pos;
}
});
if (index >= 0) {
view.dispatch(
state.tr.setSelection(NodeSelection.create(view.state.doc, index)),
);
}
};
export default selectFirstInstanceOfNode;