From 04a2c05c11b6a96d971b4bca832951b7d557e0ba Mon Sep 17 00:00:00 2001 From: khaydarov Date: Thu, 14 Jul 2016 16:09:09 +0300 Subject: [PATCH] =?UTF-8?q?fixed=20caret=20transition=20to=20empty=20list?= =?UTF-8?q?=20content=E2=80=A9=20and=20pasting=20(#75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * server-tool-link fixed bug * fixed caret transition to empty list content Fixed bug with list, URL path and block pasting. Now «paste» event inserts from buffer to the first contenteditable element * pasting to the block from Buffer in selected contenteditable element --- codex-editor.js | 165 +++++++++---------------------------------- plugins/list/list.js | 5 +- server/index.php | 10 +-- 3 files changed, 42 insertions(+), 138 deletions(-) diff --git a/codex-editor.js b/codex-editor.js index b25bee30..5bc201bf 100644 --- a/codex-editor.js +++ b/codex-editor.js @@ -850,13 +850,19 @@ cEditor.callback = { var clipboardData, pastedData, nodeContent; + /** Prevent Default Browser behaviour */ event.preventDefault(); clipboardData = event.clipboardData || window.clipboardData; pastedData = clipboardData.getData('Text'); nodeContent = document.createTextNode(pastedData); - block.appendChild(nodeContent); + + var index = cEditor.caret.getCurrentInputIndex(); + + /** Insert parsed content to the editable block */ + var editableElement = cEditor.state.inputs[index]; + editableElement.appendChild(nodeContent); }, /** @@ -1031,84 +1037,6 @@ cEditor.content = { cEditor.content.workingNodeChanged(newBlock); }, - /** - * @deprecated with replaceBlock() - */ - _switchBlock : function (targetBlock, newBlockTagname) { - - if (!targetBlock || !newBlockTagname) return; - - var nodeToReplace; - - /** - * First-level nodes replaces as-is, - * otherwise we need to replace parent node - */ - if (cEditor.parser.isFirstLevelBlock(targetBlock)) { - nodeToReplace = targetBlock; - } else { - nodeToReplace = targetBlock.parentNode; - } - - /** - * Make new node with original content - */ - var nodeCreated = cEditor.draw.block(newBlockTagname, targetBlock.innerHTML); - - /** Mark node as redactor block */ - nodeCreated.contentEditable = "true"; - nodeCreated.classList.add(cEditor.ui.BLOCK_CLASSNAME); - - /** - * If it is a first-level node, replace as-is. - */ - if (cEditor.parser.isFirstLevelBlock(nodeCreated)) { - - cEditor.nodes.redactor.replaceChild(nodeCreated, nodeToReplace); - - /** - * Set new node as current - */ - - cEditor.content.workingNodeChanged(nodeCreated); - - /** - * Setting caret - */ - cEditor.caret.set(nodeCreated); - - /** Add event listeners for created node */ - cEditor.ui.addBlockHandlers(nodeCreated); - - return; - - } - - /** - * If it is not a first-level node, for example LI or IMG - * we need to wrap it in block-tag (

or