UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

24 lines 1.07 kB
import { ReplaceStep } from '../../prosemirror'; import { createSliceWithContent } from '../../utils'; export function transformToCodeAction(state, from, to) { var replaceSteps = []; var tr = state.tr; // Traverse through all the nodes within the range and replace them with their plaintext counterpart state.doc.nodesBetween(from, to, function (node, nodePos) { var cur = nodePos; var end = cur + node.nodeSize; if (node.type === state.schema.nodes.mention) { var content = node.attrs.text; replaceSteps.push(new ReplaceStep(cur, end, createSliceWithContent(content, state), false)); } }); // Step from the end so that we don't have to recalculate the positions for (var i = replaceSteps.length - 1; i >= 0; i--) { tr.step(replaceSteps[i]); } var updatedTo = state.apply(tr).selection.to; var codeMark = state.schema.marks.code.create(); tr.addMark(from, updatedTo, codeMark).setStoredMarks([codeMark]); return tr; } //# sourceMappingURL=transform-to-code.js.map