Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
editor.addUndoSnapshot(() => {
element.parentNode.insertBefore(div, element);
// Select the new line when we are in table. This is the same behavior with Word
if (getTagOfNode(element) == 'TABLE') {
editor.select(new Position(div, PositionType.Begin).normalize());
}
});
event.rawEvent.preventDefault();
// Only reason we don't get the selection block is that we have an empty content div
// which can happen when users removes everything (i.e. select all and DEL, or backspace from very end to begin)
// The fix is to add a DIV wrapping, apply default format and move cursor over
formatNode = fromHtml(
Browser.isEdge ? '<div><span><br></span></div>' : '<div><br></div>',
this.editor.getDocument()
)[0] as HTMLElement;
this.editor.insertNode(formatNode, {
position: ContentPosition.End,
updateCursor: false,
replaceSelection: false,
insertOnNewLine: false,
});
// element points to a wrapping node we added "<div><br></div>". We should move the selection left to <br>
result = new Position(formatNode.firstChild, PositionType.Begin);
}
if (formatNode) {
applyFormat(formatNode, this.editor.getDefaultFormat(), this.editor.isDarkMode());
}
return result;
}
onPluginEvent(event: PluginEvent) {
if (event.eventType == PluginEventType.KeyPress) {
let range = this.editor.getSelectionRange();
if (range && range.collapsed && this.editor.getElementAtCursor('A[href]')) {
let searcher = cacheGetContentSearcher(event, this.editor);
let inlineElement = searcher.getInlineElementBefore();
if (inlineElement instanceof LinkInlineElement) {
this.editor.select(
new Position(inlineElement.getContainerNode(), PositionType.After)
);
}
}
}
}
}
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;
};
editor.runAsync(() => editor.select(new Position(table, PositionType.Begin).normalize()));
}, ChangeSource.Format);
editor.runAsync(() => {
let newContainer = editor.getElementAtCursor();
if (
contains(vtable.table, newContainer) &&
!contains(td, newContainer, true /*treatSameNodeAsContain*/)
) {
let newPos = targetTd
? new Position(targetTd, PositionType.Begin)
: new Position(vtable.table, isUp ? PositionType.Before : PositionType.After);
if (hasShiftKey) {
newPos =
newPos.node.nodeType == NodeType.Element && isVoidHtmlElement(newPos.node)
? new Position(
newPos.node,
newPos.isAtEnd ? PositionType.After : PositionType.Before
)
: newPos;
editor
.getSelection()
.setBaseAndExtent(anchorNode, anchorOffset, newPos.node, newPos.offset);
} else {
editor.select(newPos);
}
}
editor.runAsync(() => {
let newContainer = editor.getElementAtCursor();
if (
contains(vtable.table, newContainer) &&
!contains(td, newContainer, true /*treatSameNodeAsContain*/)
) {
let newPos = targetTd
? new Position(targetTd, PositionType.Begin)
: new Position(vtable.table, isUp ? PositionType.Before : PositionType.After);
if (hasShiftKey) {
newPos =
newPos.node.nodeType == NodeType.Element && isVoidHtmlElement(newPos.node)
? new Position(
newPos.node,
newPos.isAtEnd ? PositionType.After : PositionType.Before
)
: newPos;
editor
.getSelection()
.setBaseAndExtent(anchorNode, anchorOffset, newPos.node, newPos.offset);
} else {
editor.select(newPos);
}
}
});
},