From: Aleksander Ɓukasz Date: Wed, 20 Nov 2013 13:31:30 +0000 (+0100) Subject: integration wip: enter key X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/b95e2e87d96a747f503990f6f315ade26fe88acc integration wip: enter key --- diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index ee36332..e7f5fe8 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -47,9 +47,12 @@ handlers.push({key: KEYS.ENTER, if(Object.keys(cursor.getPosition()).length === 0) { var currentElement = canvas.getCurrentNodeElement(); if(currentElement) { - var added = currentElement.after({tag: currentElement.getWlxmlTag() || 'div', klass: currentElement.getWlxmlClass() || 'p'}); + var added = currentElement.data('wlxmlNode').after({ + tag: currentElement.getWlxmlTag() || 'div', + attrs: {'class': currentElement.getWlxmlClass() || 'p'} + }); added.append({text:''}); - canvas.setCurrentElement(added, {caretTo: 'start'}); + canvas.setCurrentElement(utils.findCanvasElement(added), {caretTo: 'start'}); } return; } @@ -71,25 +74,25 @@ handlers.push({key: KEYS.ENTER, return false; // top level element is unsplittable } - var elements = position.element.split({offset: position.offset}), + var nodes = position.element.data('wlxmlNode').split({offset: position.offset}), newEmpty, goto, gotoOptions; if(position.offsetAtBeginning) - newEmpty = elements.first; + newEmpty = nodes.first; else if(position.offsetAtEnd) - newEmpty = elements.second; + newEmpty = nodes.second; if(newEmpty) { - goto = newEmpty.append(documentElement.DocumentTextElement.create({text: ''}, this)); + goto = newEmpty.append({text: ''}); gotoOptions = {}; } else { - goto = elements.second; + goto = nodes.second; gotoOptions = {caretTo: 'start'}; } - canvas.setCurrentElement(goto, gotoOptions); + canvas.setCurrentElement(utils.findCanvasElement(goto), gotoOptions); } } }