Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const notesFromDoc = (doc, markType, min = false, max = false) => {
const notes = {};
const { from, to } = new AllSelection(doc);
const _min = min === false ? from : min;
const _max = max === false ? to : max;
doc.nodesBetween(_min, _max, (node, start) => {
const end = start + node.nodeSize;
const mark = markType.isInSet(node.marks);
if (mark) {
const { id, meta } = mark.attrs;
notes[id] = notes[id] || {
id,
meta, // this should be the same across all notes so just set it here
nodes: [],
start: Infinity,
export function selectAll(state, dispatch) {
if (dispatch) dispatch(state.tr.setSelection(new AllSelection(state.doc)))
return true
}
init: (_, state) => {
const { from, to } = new AllSelection(state.doc);
return addDecosBetween(from, to, state.doc, DecorationSet.empty);
},
apply: (tr, prevDecos, _, state) =>
export const dispatchAllSelection = ({ view }: TestEditorViewParams) => {
const { tr, doc } = view.state;
view.dispatch(tr.setSelection(new AllSelection(doc)));
};
export const initSelection = (
taggedDoc: TaggedProsemirrorNode,
) => {
const { cursor, node, start, end, anchor, all, gap } = taggedDoc.tag;
if (all) {
return new AllSelection(taggedDoc);
}
if (node) {
return new NodeSelection(taggedDoc.resolve(node));
}
if (cursor) {
return new TextSelection(taggedDoc.resolve(cursor));
}
if (gap) {
const $pos = taggedDoc.resolve(gap);
return new GapCursor($pos, $pos);
}
if (start) {
export const dispatchAllSelection = ({
view,
}: TestEditorViewParams) => {
const { tr, doc } = view.state;
view.dispatch(tr.setSelection(new AllSelection(doc)));
};