Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new DOMEventHandler(
core,
'blur',
PluginEventType.Blur,
isIEorEdge
? null
: () => {
// For browsers that do not support beforedeactivate, still do the saving selection in onBlur
// Also check if there's already a selection range cache because in Chrome onBlur can be triggered multiple times when user clicks to other places,
// in that case the second time when fetching the selection range may result in a wrong selection.
if (!core.cachedSelectionRange) {
saveSelectionRange(core);
}
}
),
new DOMEventHandler(core, 'keypress', PluginEventType.KeyPress, event => onKeyPress(core, event as KeyboardEvent)),
new DOMEventHandler(core, 'keydown', PluginEventType.KeyDown),
new DOMEventHandler(core, 'keyup', PluginEventType.KeyUp),
new DOMEventHandler(core, 'compositionstart', null, () => (core.isInIME = true)),
new DOMEventHandler(
core,
'compositionend',
PluginEventType.CompositionEnd,
() => (core.isInIME = false)
),
new DOMEventHandler(core, 'mousedown', PluginEventType.MouseDown),
new DOMEventHandler(core, 'mouseup', PluginEventType.MouseUp),
new DOMEventHandler(core, 'mouseover', PluginEventType.MouseOver),
new DOMEventHandler(core, 'mouseout', PluginEventType.MouseOut),
new DOMEventHandler(core, 'paste', PluginEventType.Paste),
new DOMEventHandler(core, 'copy', PluginEventType.Copy, () => {}),
new DOMEventHandler(core, 'focus', PluginEventType.Focus, () => {
if (this.editor.isInIME()) {
return;
}
switch (event.eventType) {
case PluginEventType.EditorReady:
if (!this.preserveSnapshots || (!this.canUndo() && !this.canRedo())) {
// Only add initial snapshot when we don't need to preserve snapshots or there is no existing snapshot
// Otherwise preserved undo/redo state may be ruined
this.addUndoSnapshot();
}
break;
case PluginEventType.KeyDown:
this.onKeyDown(event.rawEvent);
break;
case PluginEventType.KeyPress:
this.onKeyPress(event.rawEvent);
break;
case PluginEventType.CompositionEnd:
this.clearRedoForInput();
this.addUndoSnapshot();
break;
case PluginEventType.ContentChanged:
if (!this.isRestoring) {
this.clearRedoForInput();
}
break;
}
}
private createEventHandlers() {
this.eventDisposers = [
attachDomEvent(this.core, 'input', null, this.stopPropagation),
attachDomEvent(this.core, 'keypress', PluginEventType.KeyPress, this.onKeyPress),
attachDomEvent(this.core, 'keydown', PluginEventType.KeyDown, this.stopPropagation),
attachDomEvent(this.core, 'keyup', PluginEventType.KeyUp, this.stopPropagation),
attachDomEvent(this.core, 'mousedown', PluginEventType.MouseDown),
attachDomEvent(this.core, 'mouseup', PluginEventType.MouseUp),
attachDomEvent(this.core, 'compositionstart', null, () => (this.inIME = true)),
attachDomEvent(
this.core,
'compositionend',
PluginEventType.CompositionEnd,
() => (this.inIME = false)
),
attachDomEvent(this.core, 'focus', null, () => {
// Restore the last saved selection first
if (this.core.cachedSelectionRange && !this.disableRestoreSelectionOnFocus) {
restoreSelection(this.core);
}
onPluginEvent(event: PluginEvent) {
if (event.eventType == PluginEventType.KeyPress) {
let keyboardEvent = event.rawEvent;
if (keyboardEvent.which >= KEY_0 && keyboardEvent.which <= KEY_9) {
let text = NUMBERS[keyboardEvent.which - KEY_0] + ' ';
this.editor.insertContent(text);
keyboardEvent.preventDefault();
}
}
}
}
onPluginEvent(event: PluginEvent) {
if (event.eventType == PluginEventType.KeyPress) {
this.onKeyPress(event);
}
}
onPluginEvent(e: PluginEvent) {
if (
e.eventType == PluginEventType.KeyPress ||
e.eventType == PluginEventType.ContentChanged
) {
if (this.checkGetBlocks.current.checked) {
this.update();
} else {
this.setBlocks([]);
}
}
}
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)
);
}
}
}
}
}
private renderEvent(event: PluginEvent): JSX.Element {
switch (event.eventType) {
case PluginEventType.KeyDown:
case PluginEventType.KeyPress:
case PluginEventType.KeyUp:
return (
<span>
Key=
{event.rawEvent.which}
</span>
);
case PluginEventType.MouseDown:
case PluginEventType.MouseUp:
return (
<span>
Button=
{event.rawEvent.button}, SrcElement=
{event.rawEvent.target && getTagOfNode(event.rawEvent.target as Node)},
PageX=
</span>