Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tr.doc.nodesBetween(startPos, endPos, (node, pos) => {
if (
node.isText || // Text node
(node.isTextblock && !node.textContent) // Empty paragraph
) {
const res = tr.doc.resolve(tr.mapping.map(pos));
const sel = new NodeSelection(res);
const range = nullthrows(sel.$from.blockRange(sel.$to));
const target = liftTarget(range);
if (target || target === 0) {
tr = tr.lift(range, target);
}
}
});
function selectHorizontally(view, dir, mods) {
let sel = view.state.selection
if (sel instanceof TextSelection) {
if (!sel.empty || mods.indexOf("s") > -1) {
return false
} else if (view.endOfTextblock(dir > 0 ? "right" : "left")) {
let next = moveSelectionBlock(view.state, dir)
if (next && (next instanceof NodeSelection)) return apply(view, next)
return false
} else {
let $head = sel.$head, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter, desc
if (!node || node.isText) return false
let nodePos = dir < 0 ? $head.pos - node.nodeSize : $head.pos
if (!(node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false
if (NodeSelection.isSelectable(node)) {
return apply(view, new NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node.nodeSize) : $head))
} else if (browser.webkit) {
// Chrome and Safari will introduce extra pointless cursor
// positions around inline uneditable nodes, so we have to
// take over and move the cursor past them (#937)
return apply(view, new TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize)))
} else {
return false
}
}
} else if (sel instanceof NodeSelection && sel.node.isInline) {
return apply(view, new TextSelection(dir > 0 ? sel.$to : sel.$from))
} else {
let next = moveSelectionBlock(view.state, dir)
if (next) return apply(view, next)
return false
}
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)
}
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 selectClickedLeaf(view, inside) {
if (inside == -1) return false
let $pos = view.state.doc.resolve(inside), node = $pos.nodeAfter
if (node && node.isAtom && NodeSelection.isSelectable(node)) {
updateSelection(view, new NodeSelection($pos), "pointer")
return true
}
return false
}
handleImageViewClick () {
let tr = this.view.state.tr;
const pos = this.getPos();
let pos1 = this.view.state.doc.resolve(pos);
let selection = new NodeSelection(pos1);
tr.setSelection(selection);
this.view.dispatch(tr);
},
},
let tr = view.state.tr
if (dragging && dragging.move) tr.deleteSelection()
let pos = tr.mapping.map(insertPos)
let isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1
let beforeInsert = tr.doc
if (isNode)
tr.replaceRangeWith(pos, pos, slice.content.firstChild)
else
tr.replaceRange(pos, pos, slice)
if (tr.doc.eq(beforeInsert)) return
let $pos = tr.doc.resolve(pos)
if (isNode && NodeSelection.isSelectable(slice.content.firstChild) &&
$pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild))
tr.setSelection(new NodeSelection($pos))
else
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(tr.mapping.map(insertPos))))
view.focus()
view.dispatch(tr.setMeta("uiEvent", "drop"))
}
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) {
return createTextSelection({ taggedDoc, start, end });
}
const $anchor = resolveCell(taggedDoc, anchor);