Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function selFor(doc) {
let a = doc.tag.a
if (a != null) {
let $a = doc.resolve(a)
if ($a.parent.inlineContent) return new TextSelection($a, doc.tag.b != null ? doc.resolve(doc.tag.b) : undefined)
else return new NodeSelection($a)
}
return Selection.atStart(doc)
}
const selFor = initDoc => {
const { a } = initDoc.tag;
if (a !== null) {
const $a = initDoc.resolve(a);
if ($a.parent.inlineContent) {
const { b } = initDoc.tag;
const $b = b ? initDoc.resolve(b) : undefined;
return new TextSelection($a, $b);
} else {
return new NodeSelection($a);
}
}
return Selection.atStart(doc);
};
function selFor(doc) {
let a = doc.tag.a
if (a != null) {
let $a = doc.resolve(a)
if ($a.parent.inlineContent) return new TextSelection($a, doc.tag.b != null ? doc.resolve(doc.tag.b) : undefined)
else return new NodeSelection($a)
}
return Selection.atStart(doc)
}
export const findNodeAtStartOfDoc = (doc: ProsemirrorNode) =>
findNodeAtPosition(PMSelection.atStart(doc).$from);
"Mod-a": (state, dispatch) => {
const textSelection = new TextSelection(
Selection.atStart(state.doc).$anchor,
Selection.atEnd(state.doc).$head
);
dispatch(state.tr.setSelection(textSelection));
return true;
}
});
export const selectionFor = (
taggedDoc: TaggedProsemirrorNode,
): Selection => {
return initSelection(taggedDoc) ?? Selection.atStart(taggedDoc);
};
export const importDocJson = (editorView, docJson) => {
const doc = Node.fromJSON(editorView.state.schema, docJson);
const tr = editorView.state.tr;
tr.setSelection(Selection.atStart(editorView.state.doc));
tr.replaceSelection(new Slice(doc.content, 0, 0));
editorView.dispatch(tr);
return doc;
};