Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.dataProvider.selectOption &&
(keyboardEvent.key == ENTER_CHARCODE || keyboardEvent.key == TAB_CHARCODE)
) {
this.dataProvider.selectOption();
this.cancelDefaultKeyDownEvent(event);
} else {
// Currently no op.
}
} else {
if (keyboardEvent.key == BACKSPACE_CHARCODE) {
const nodeRemoved = this.tryRemoveNode(event);
if (nodeRemoved) {
this.cancelDefaultKeyDownEvent(event);
}
} else if (keyboardEvent.key == DELETE_CHARCODE) {
let searcher = cacheGetContentSearcher(event, this.editor);
let nodeAfterCursor = searcher.getInlineElementAfter()
? searcher.getInlineElementAfter().getContainerNode()
: null;
let nodeId = nodeAfterCursor ? this.getIdValue(nodeAfterCursor) : null;
if (nodeId && nodeId.indexOf(this.pickerOptions.elementIdPrefix) == 0) {
let replacementNode = this.dataProvider.onRemove(nodeAfterCursor, false);
this.replaceNode(nodeAfterCursor, replacementNode);
this.cancelDefaultKeyDownEvent(event);
}
}
}
}
private getRangeUntilAt(event: PluginKeyboardEvent): Range {
let PositionContentSearcher = cacheGetContentSearcher(event, this.editor);
let startPos: NodePosition;
let endPos: NodePosition;
PositionContentSearcher.forEachTextInlineElement(textInline => {
let hasMatched = false;
let nodeContent = textInline.getTextContent();
let nodeIndex = nodeContent ? nodeContent.length : -1;
while (nodeIndex >= 0) {
if (nodeContent[nodeIndex] == this.pickerOptions.triggerCharacter) {
startPos = textInline.getStartPosition().move(nodeIndex);
hasMatched = true;
break;
}
nodeIndex--;
}
if (hasMatched) {
private _getWordBeforeCursor(event: PluginEvent): string {
const cursorData = cacheGetContentSearcher(event, this._editor);
const wordBeforeCursor = cursorData ? cursorData.getWordBefore() : null;
const matches = EMOJI_BEFORE_COLON_REGEX.exec(wordBeforeCursor);
return matches && matches.length > 2 && matches[0] === wordBeforeCursor ? matches[2] : null;
}
private getInlineElementBeforeCursor(event: PluginEvent): string {
const searcher = cacheGetContentSearcher(event, this.editor);
const element = searcher ? searcher.getInlineElementBefore() : null;
return element ? element.getTextContent() : null;
}
}
private tryRemoveNode(event: PluginDomEvent): boolean {
const searcher = cacheGetContentSearcher(event, this.editor);
const inlineElementBefore = searcher.getInlineElementBefore();
const nodeBeforeCursor = inlineElementBefore
? inlineElementBefore.getContainerNode()
: null;
const nodeId = nodeBeforeCursor ? this.getIdValue(nodeBeforeCursor) : null;
const inlineElementAfter = searcher.getInlineElementAfter();
if (
nodeId &&
nodeId.indexOf(this.pickerOptions.elementIdPrefix) == 0 &&
(inlineElementAfter == null || !(inlineElementAfter instanceof PartialInlineElement))
) {
const replacementNode = this.dataProvider.onRemove(nodeBeforeCursor, true);
if (replacementNode) {
this.replaceNode(nodeBeforeCursor, replacementNode);
if (this.isPendingInputEventHandling) {