MCPcopy
hub / github.com/codex-team/editor.js / processInlinePaste

Method processInlinePaste

src/components/modules/paste.ts:772–806  ·  view source on GitHub ↗

* Process paste to single Block: * 1. Find patterns` matches * 2. Insert new block if it is not the same type as current one * 3. Just insert text if there is no substitutions * * @param {PasteData} dataToInsert - data of Block to insert

(dataToInsert: PasteData)

Source from the content-addressed store, hash-verified

770 * @param {PasteData} dataToInsert - data of Block to insert
771 */
772 private async processInlinePaste(dataToInsert: PasteData): Promise<void> {
773 const { BlockManager, Caret } = this.Editor;
774 const { content } = dataToInsert;
775
776 const currentBlockIsDefault = BlockManager.currentBlock && BlockManager.currentBlock.tool.isDefault;
777
778 if (currentBlockIsDefault && content.textContent.length < Paste.PATTERN_PROCESSING_MAX_LENGTH) {
779 const blockData = await this.processPattern(content.textContent);
780
781 if (blockData) {
782 const needToReplaceCurrentBlock = BlockManager.currentBlock &&
783 BlockManager.currentBlock.tool.isDefault &&
784 BlockManager.currentBlock.isEmpty;
785
786 const insertedBlock = BlockManager.paste(blockData.tool, blockData.event, needToReplaceCurrentBlock);
787
788 Caret.setToBlock(insertedBlock, Caret.positions.END);
789
790 return;
791 }
792 }
793
794 /** If there is no pattern substitute - insert string as it is */
795 if (BlockManager.currentBlock && BlockManager.currentBlock.currentInput) {
796 const currentToolSanitizeConfig = BlockManager.currentBlock.tool.baseSanitizeConfig;
797
798 document.execCommand(
799 'insertHTML',
800 false,
801 clean(content.innerHTML, currentToolSanitizeConfig)
802 );
803 } else {
804 this.insertBlock(dataToInsert);
805 }
806 }
807
808 /**
809 * Get patterns` matches

Callers 1

processTextMethod · 0.95

Calls 5

processPatternMethod · 0.95
insertBlockMethod · 0.95
cleanFunction · 0.90
pasteMethod · 0.65
setToBlockMethod · 0.65

Tested by

no test coverage detected