本文整理汇总了TypeScript中prosemirror-state.Selection类的典型用法代码示例。如果您正苦于以下问题:TypeScript Selection类的具体用法?TypeScript Selection怎么用?TypeScript Selection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Selection类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: selectAroundMark
selectAroundMark(markType: MarkType, doc: Node, pos: number, dispatchTransaction): Mark {
let $pos = doc.resolve(pos),
parent = $pos.parent;
let start = parent.childAfter($pos.parentOffset);
if (!start.node || start.node.marks.length === 0) {
// happens if the cursor is at the end of the line or the end of the node, use nodeAt pos - 1 to find node marks
start.node = parent.nodeAt($pos.parentOffset - 1);
if (!start.node) {
return null;
}
}
let targetMark = start.node.marks.find(mark => mark.type.name === markType.name);
if (!targetMark) {
return null;
}
let startIndex = $pos.index(),
startPos = $pos.start() + start.offset;
while (startIndex > 0 && targetMark.isInSet(parent.child(startIndex - 1).marks)) {
startPos -= parent.child(--startIndex).nodeSize;
}
let endIndex = $pos.indexAfter(),
endPos = startPos + start.node.nodeSize;
while (endPos < parent.childCount && targetMark.isInSet(parent.child(endIndex).marks)) {
endPos += parent.child(endIndex++).nodeSize;
}
let selection = Selection.between(doc.resolve(startPos), doc.resolve(endPos));
dispatchTransaction(this.view.editor.state.tr.setSelection(selection));
return targetMark;
}
示例2: filterCommands
return filterCommands(canLinkBeCreatedInRange(from, to), (state, dispatch) => {
const link = state.schema.marks.link
if (href.trim()) {
const { tr } = state
if (from === to) {
const textContent = text || href
tr.insertText(textContent, from, to)
tr.addMark(
from,
from + textContent.length,
link.create({ href: normalizeUrl(href) }),
)
} else {
tr.addMark(from, to, link.create({ href: normalizeUrl(href) }))
tr.setSelection(Selection.near(tr.doc.resolve(to)))
}
// queueCardsFromChangedTr(state, tr);
if (dispatch) {
tr.setMeta(pluginKey, LinkAction.HIDE_TOOLBAR)
dispatch(tr)
}
return true
}
return false
})
示例3: function
return function(state: EditorState, dispatch) {
let { tr } = state
const { $from, $to } = state.selection
const { paragraph } = state.schema.nodes
const { alignment, indentation } = state.schema.marks
/** Alignment or Indentation is not valid inside block types */
const removeAlignTr = removeBlockMarks(state, [alignment, indentation])
tr = removeAlignTr || tr
const range = $from.blockRange($to) as any
const wrapping = range && (findWrapping(range, type) as any)
if (range && wrapping) {
tr.wrap(range, wrapping).scrollIntoView()
} else {
/** We always want to append a block type */
tr.replaceRangeWith(
$to.pos + 1,
$to.pos + 1,
type.createAndFill({}, paragraph.create()),
)
tr.setSelection(Selection.near(tr.doc.resolve(state.selection.to + 1)))
}
if (dispatch) {
dispatch(tr)
}
return true
}
示例4:
const getActiveText = (schema: Schema, selection: Selection): string | undefined => {
const currentSlice = selection.content()
if (currentSlice.size === 0) {
return
}
if (
currentSlice.content.childCount === 1 &&
[schema.nodes.paragraph, schema.nodes.text].indexOf(
currentSlice.content.firstChild.type,
) !== -1
) {
return currentSlice.content.firstChild.textContent
}
}
示例5: function
return function(state: EditorState, dispatch) {
const { tr } = state
const { $to } = state.selection
const { codeBlock } = state.schema.nodes
const getNextNode = state.doc.nodeAt($to.pos + 1)
const addPos = getNextNode && getNextNode.isText ? 0 : 1
/** We always want to append a block type */
tr.replaceRangeWith($to.pos + addPos, $to.pos + addPos, codeBlock.createAndFill() as Node)
tr.setSelection(Selection.near(tr.doc.resolve(state.selection.to + addPos)))
if (dispatch) {
dispatch(tr)
}
return true
}
示例6: selectionFor
function selectionFor(docNode: pm.TaggedProsemirrorNode) {
const aTag = docNode.tag.a;
if (aTag != null) {
const $aTag = docNode.resolve(aTag);
if ($aTag.parent.inlineContent) {
return new TextSelection(
$aTag,
docNode.tag.b != null
? docNode.resolve(docNode.tag.b)
: undefined,
);
} else {
return new NodeSelection($aTag);
}
}
return Selection.atStart(docNode);
}
示例7:
transaction = transaction.delete(0, 0);
transaction = transaction.addMark(0, 0, mark);
transaction = transaction.removeMark(0, 0);
transaction = transaction.clearIncompatible(0, nodeType);
transaction = transaction.replaceRange(0, 0, slice);
transaction = transaction.replaceRangeWith(0, 0, node);
transaction = transaction.deleteRange(0, 0);
transaction = transaction.delete(0, 0);
transaction = transaction.replace(0, 0);
transaction = transaction.replaceWith(0, 0, node);
transaction = transaction.insert(0, node);
transaction = transaction.lift(nodeRange, 0);
transaction = transaction.wrap(nodeRange, []);
transaction = transaction.setBlockType(0, 0, node.type);
transaction = transaction.setNodeMarkup(0);
transaction = transaction.split(0);
transaction = transaction.join(0);
transaction = transaction.step(step);
const res1_1: state.PluginSpec["appendTransaction"] = null;
const res1_2: state.PluginSpec["appendTransaction"] = () => {};
const res1_3: state.PluginSpec["appendTransaction"] = () => null;
const res1_4: state.PluginSpec["appendTransaction"] = () => undefined;
const res1_5: state.PluginSpec["appendTransaction"] = () => ({} as state.Transaction);
const res2_1 = new state.PluginKey();
const res2_2: state.Plugin = res2_1.get({} as state.EditorState)!;
const res3_1 = new state.Selection({} as any, {} as any);
const res3_2: state.Selection = state.Selection.findFrom({} as model.ResolvedPos, 0)!;