Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
let pos = Position.getStart(range);
let blockElement: BlockElement;
if (
option.insertOnNewLine &&
(blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
) {
pos = new Position(blockElement.getEndNode(), PositionType.After);
} else {
pos = adjustNodeInsertPosition(contentDiv, node, pos);
}
let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
range = createRange(pos);
range.insertNode(node);
if (option.updateCursor && nodeForCursor) {
rangeToRestore = createRange(
new Position(nodeForCursor, PositionType.After).normalize()
);
}
core.api.selectRange(core, rangeToRestore);
break;
case ContentPosition.Outside:
core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
break;
}
return true;
};
let blockElement: BlockElement;
if (
option.insertOnNewLine &&
(blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
) {
pos = new Position(blockElement.getEndNode(), PositionType.After);
} else {
pos = adjustNodeInsertPosition(contentDiv, node, pos);
}
let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
range = createRange(pos);
range.insertNode(node);
if (option.updateCursor && nodeForCursor) {
rangeToRestore = createRange(
new Position(nodeForCursor, PositionType.After).normalize()
);
}
core.api.selectRange(core, rangeToRestore);
break;
case ContentPosition.Outside:
core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
break;
}
return true;
};
}
let pos = Position.getStart(range);
let blockElement: BlockElement;
if (
option.insertOnNewLine &&
(blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
) {
pos = new Position(blockElement.getEndNode(), PositionType.After);
} else {
pos = adjustNodeInsertPosition(contentDiv, node, pos);
}
let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
range = createRange(pos);
range.insertNode(node);
if (option.updateCursor && nodeForCursor) {
rangeToRestore = createRange(
new Position(nodeForCursor, PositionType.After).normalize()
);
}
core.api.selectRange(core, rangeToRestore);
break;
case ContentPosition.Outside:
core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
break;
}
return true;
};
let blockElement: BlockElement;
if (
option.insertOnNewLine &&
(blockElement = getBlockElementAtNode(contentDiv, pos.normalize().node))
) {
pos = new Position(blockElement.getEndNode(), PositionType.After);
} else {
pos = adjustNodeInsertPosition(contentDiv, node, pos);
}
let nodeForCursor = node.nodeType == NodeType.DocumentFragment ? node.lastChild : node;
range = createRange(pos);
range.insertNode(node);
if (option.updateCursor && nodeForCursor) {
rangeToRestore = createRange(
new Position(nodeForCursor, PositionType.After).normalize()
);
}
core.api.selectRange(core, rangeToRestore);
break;
case ContentPosition.Outside:
core.contentDiv.parentNode.insertBefore(node, contentDiv.nextSibling);
break;
}
return true;
};
while (nodeIndex >= 0) {
if (nodeContent[nodeIndex] == this.pickerOptions.triggerCharacter) {
startPos = textInline.getStartPosition().move(nodeIndex);
hasMatched = true;
break;
}
nodeIndex--;
}
if (hasMatched) {
endPos = textInline.getEndPosition();
}
return hasMatched;
});
return createRange(startPos, endPos) || this.editor.getDocument().createRange();
}
function getTextContent(block: BlockElement): string {
return block.getStartNode() == block.getEndNode()
? block.getStartNode().textContent
: createRange(block.getStartNode(), block.getEndNode()).toString();
}
export const select: Select = (core: EditorCore, arg1: any, arg2?: any, arg3?: any, arg4?: any) => {
let range = arg1 instanceof Range ? arg1 : createRange(arg1, arg2, arg3, arg4);
return core.api.selectRange(core, range);
};