How to use the roosterjs-editor-types.PluginEventType.KeyPress function in roosterjs-editor-types

To help you get started, we’ve selected a few roosterjs-editor-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / createEventHandlers.ts View on Github external
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, () => {
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / undo / Undo.ts View on Github external
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;
        }
    }
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / editor / Editor.ts View on Github external
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);
                }
github microsoft / roosterjs / publish / samplecode / 7 / source.ts View on Github external
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();
            }
        }
    }
}
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / corePlugins / TypeInContainerPlugin.ts View on Github external
onPluginEvent(event: PluginEvent) {
        if (event.eventType == PluginEventType.KeyPress) {
            this.onKeyPress(event);
        }
    }
github microsoft / roosterjs / publish / samplesite / scripts / controls / sidePane / apiPlayground / blockElements / BlockElementsPane.tsx View on Github external
onPluginEvent(e: PluginEvent) {
        if (
            e.eventType == PluginEventType.KeyPress ||
            e.eventType == PluginEventType.ContentChanged
        ) {
            if (this.checkGetBlocks.current.checked) {
                this.update();
            } else {
                this.setBlocks([]);
            }
        }
    }
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / corePlugins / FirefoxTypeAfterLink.ts View on Github external
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)
                    );
                }
            }
        }
    }
}
github microsoft / roosterjs / publish / samplesite / scripts / controls / sidePane / eventViewer / EventViewPane.tsx View on Github external
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 &amp;&amp; getTagOfNode(event.rawEvent.target as Node)},
                        PageX=
</span>