diff --git a/src/components/modules/paste.ts b/src/components/modules/paste.ts index bdbec4458..2563e5693 100644 --- a/src/components/modules/paste.ts +++ b/src/components/modules/paste.ts @@ -109,6 +109,7 @@ interface PasteData { * @version 2.0.0 */ export default class Paste extends Module { + public pasteEvent; /** If string`s length is greater than this number we don't check paste patterns */ public static readonly PATTERN_PROCESSING_MAX_LENGTH = 450; @@ -224,6 +225,30 @@ export default class Paste extends Module { } } + /** + * Check if elem has input class in parents html elements + * + * @param {HTMLElement} elem - pasted or dropped data transfer object + */ + public isDomElementInCdxInput(elem): boolean { + const { StylesAPI } = this.Editor; + const elements = document.querySelectorAll(`.${StylesAPI.classes.input}`); + + try { + for (const i in elements) { + if (elements[i] && elements[i].contains(elem)) { + return true; + } + } + + return false; + } catch (e) { + console.log(e); + + return false; + } + } + /** * Process pasted text and divide them into Blocks * @@ -238,6 +263,29 @@ export default class Paste extends Module { return; } + if (this.pasteEvent && this.pasteEvent.target && this.isDomElementInCdxInput(this.pasteEvent.target)) { + const p = document.createElement('p'); + + p.innerText = ''; + dataToInsert.forEach((item, index) => { + p.innerText = p.innerText + item.content.innerText; + + if (index => { const { BlockManager, Toolbar } = this.Editor; - + this.pasteEvent = event; /** * When someone pasting into a block, its more stable to set current block by event target, instead of relying on current block set before */