UNPKG

@atlaskit/editor-plugin-highlight

Version:

Highlight plugin for @atlaskit/editor-core

41 lines 1.03 kB
export const isHighlightedTextNode = node => { return node.isText && node.marks.some(mark => mark.type.name === 'backgroundColor'); }; export const shouldPadLeft = ({ state, nodeStart }) => { const $pos = state.doc.resolve(nodeStart); const isAtBlockStart = $pos.parentOffset === 0; if (isAtBlockStart) { return true; } const isAtDocStart = nodeStart === 0; if (isAtDocStart) { return true; } const isPrevCharSpace = state.doc.textBetween(nodeStart - 1, nodeStart) === ' '; if (isPrevCharSpace) { return true; } return false; }; export const shouldPadRight = ({ state, nodeEnd }) => { const $pos = state.doc.resolve(nodeEnd); const isAtBlockEnd = $pos.parentOffset === $pos.parent.content.size; if (isAtBlockEnd) { return true; } const isAtDocEnd = nodeEnd === state.doc.content.size; if (isAtDocEnd) { return true; } const isNextCharSpace = state.doc.textBetween(nodeEnd, nodeEnd + 1) === ' '; if (isNextCharSpace) { return true; } return false; };