How to use the roosterjs-editor-core.cacheGetContentSearcher function in roosterjs-editor-core

To help you get started, we’ve selected a few roosterjs-editor-core 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-plugin-picker / lib / PickerPlugin.ts View on Github external
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);
                }
            }
        }
    }
github microsoft / roosterjs / packages / roosterjs-plugin-picker / lib / PickerPlugin.ts View on Github external
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) {
github microsoft / roosterjs-react / packages / roosterjs-react-emoji / lib / plugins / EmojiPlugin.tsx View on Github external
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;
    }
github microsoft / roosterjs / packages / roosterjs-plugin-picker / lib / PickerPlugin.ts View on Github external
private getInlineElementBeforeCursor(event: PluginEvent): string {
        const searcher = cacheGetContentSearcher(event, this.editor);
        const element = searcher ? searcher.getInlineElementBefore() : null;
        return element ? element.getTextContent() : null;
    }
}
github microsoft / roosterjs / packages / roosterjs-plugin-picker / lib / PickerPlugin.ts View on Github external
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) {