* Process pasted text and divide them into Blocks * * @param {string} data - text to process. Can be HTML or plain. * @param {boolean} isHTML - if passed string is HTML, this parameter should be true
(data: string, isHTML = false)
| 231 | * @param {boolean} isHTML - if passed string is HTML, this parameter should be true |
| 232 | */ |
| 233 | public async processText(data: string, isHTML = false): Promise<void> { |
| 234 | const { Caret, BlockManager } = this.Editor; |
| 235 | const dataToInsert = isHTML ? this.processHTML(data) : this.processPlain(data); |
| 236 | |
| 237 | if (!dataToInsert.length) { |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | if (dataToInsert.length === 1) { |
| 242 | if (!dataToInsert[0].isBlock) { |
| 243 | this.processInlinePaste(dataToInsert.pop()); |
| 244 | } else { |
| 245 | this.processSingleBlock(dataToInsert.pop()); |
| 246 | } |
| 247 | |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | const isCurrentBlockDefault = BlockManager.currentBlock && BlockManager.currentBlock.tool.isDefault; |
| 252 | const needToReplaceCurrentBlock = isCurrentBlockDefault && BlockManager.currentBlock.isEmpty; |
| 253 | |
| 254 | dataToInsert.map( |
| 255 | async (content, i) => this.insertBlock(content, i === 0 && needToReplaceCurrentBlock) |
| 256 | ); |
| 257 | |
| 258 | if (BlockManager.currentBlock) { |
| 259 | Caret.setToBlock(BlockManager.currentBlock, Caret.positions.END); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Set onPaste callback handler |
no test coverage detected