UNPKG

@atlaskit/editor-plugin-code-block

Version:

Code block plugin for @atlaskit/editor-core

41 lines 1.13 kB
export function getCursor(selection) { return selection.$cursor || undefined; } export function getAllCodeBlockNodesInDoc(state) { var codeBlockNodes = []; state.doc.descendants(function (node, pos) { if (node.type === state.schema.nodes.codeBlock) { codeBlockNodes.push({ node: node, pos: pos }); return false; } return true; }); return codeBlockNodes; } export function getAllChangedCodeBlocksInTransaction(tr) { var changedCodeBlocks = []; var nodePositions = new Set(); tr.steps.forEach(function (step) { var mapResult = step.getMap(); mapResult.forEach(function (oldStart, oldEnd, newStart, newEnd) { tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node, pos) { if (node.type.name === 'codeBlock') { if (!nodePositions.has(pos)) { nodePositions.add(pos); changedCodeBlocks.push({ node: node, pos: pos }); } } }); }); }); if (changedCodeBlocks.length < 1) { return null; } return changedCodeBlocks; }