X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/b95e2e87d96a747f503990f6f315ade26fe88acc..75d2183aafd4b2d3e94c17f6c3c8ee0d8a4738e4:/src/editor/modules/documentCanvas/canvas/keyboard.js diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index e7f5fe8..418dc93 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -74,22 +74,33 @@ handlers.push({key: KEYS.ENTER, return false; // top level element is unsplittable } - var nodes = position.element.data('wlxmlNode').split({offset: position.offset}), - newEmpty, - goto, - gotoOptions; - - if(position.offsetAtBeginning) - newEmpty = nodes.first; - else if(position.offsetAtEnd) - newEmpty = nodes.second; + //var nodes = position.element.data('wlxmlNode').split({offset: position.offset}), + // var nodes = position.element.data('wlxmlNode').transform('split', {offset: position.offset}), + // newEmpty, + // goto, + // gotoOptions; + + // if(position.offsetAtBeginning) + // newEmpty = nodes.first; + // else if(position.offsetAtEnd) + // newEmpty = nodes.second; - if(newEmpty) { - goto = newEmpty.append({text: ''}); + // if(newEmpty) { + // //goto = newEmpty.append({text: ''}); + // gotoOptions = {}; + // } else { + // goto = nodes.second; + // gotoOptions = {caretTo: 'start'}; + // } + + var result = position.element.data('wlxmlNode').transform('rng.breakContent', {offset: position.offset}), + goto, gotoOptions; + if(result.emptyText) { + goto = result.createdEmpty; gotoOptions = {}; } else { - goto = nodes.second; - gotoOptions = {caretTo: 'start'}; + goto = result.second; + gotoOptions = {caretTo: 'start'}; } canvas.setCurrentElement(utils.findCanvasElement(goto), gotoOptions); @@ -189,14 +200,14 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE], goto; if(parent.children().length === 1 && parent.children()[0].sameNode(element)) { if(grandParent && grandParent.children().length === 1) { - goto = grandParent.append({text: ''}); + goto = grandParent.data('wlxmlNode').append({text: ''}); } else { goto = element.getNearestTextElement(direction); } - parent.detach(); + parent.data('wlxmlNode').detach(); } else { goto = element.getNearestTextElement(direction); - element.detach(); + element.data('wlxmlNode').detach(); } canvas.setCurrentElement(goto, {caretTo: caretTo}); canvas.publisher('contentChanged');