X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/3c4f1543aaf955e96a526b4fe13688645e14e720..4c81ad4075b0e8e67f984cce3494f9853179a9d6:/modules/documentCanvas/documentCanvas.js?ds=sidebyside diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index d8c199b..1577be0 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -14,6 +14,7 @@ return function(sandbox) { node: $(_.template(template)()), currentNode: null, shownAlready: false, + scrollbarPosition: 0, setup: function() { var view = this; @@ -50,6 +51,15 @@ return function(sandbox) { e.preventDefault(); view.insertNewNode(null, null); } + if(e.which === 8) { + var anchor = window.getSelection().anchorNode; + var len = anchor.length; + console.log(len); + if(len === 1) { + e.preventDefault(); + $(anchor).parent().text(''); + } + } }); this.node.onShow = function() { @@ -57,9 +67,13 @@ return function(sandbox) { view.shownAlready = true; view.selectFirstNode(); } else if(view.currentNode) { - view.moveCarretToNode(view.getNodeElement(view.currentNode)); + view.movecaretToNode(view.getNodeElement(view.currentNode)); + view.node.find('#rng-module-documentCanvas-contentWrapper').scrollTop(view.scrollbarPosition); } }; + this.node.onHide = function() { + view.scrollbarPosition = view.node.find('#rng-module-documentCanvas-contentWrapper').scrollTop(); + } this.gridToggled = false; }, @@ -77,14 +91,17 @@ return function(sandbox) { //TODO: Insert inline var anchor = $(window.getSelection().anchorNode); var anchorOffset = window.getSelection().anchorOffset; - if(anchor[0].nodeType === Node.TEXT_NODE) + var textLen; + if(anchor[0].nodeType === Node.TEXT_NODE) { + textLen = anchor.text().length; anchor = anchor.parent(); + } if(anchor.text() === '') { var todel = anchor; anchor = anchor.parent(); todel.remove(); } - if(anchorOffset > 0 && anchorOffset < anchor.text().length) { + if(anchorOffset > 0 && anchorOffset < textLen) { if(wlxmlTag === null && wlxmlClass === null) { return this.splitWithNewNode(anchor); } @@ -95,7 +112,7 @@ return function(sandbox) { anchor.before(newNode) else anchor.after(newNode); - this.selectNode(new wlxmlNode.Node(newNode), {moveCarret: true}); + this.selectNode(new wlxmlNode.Node(newNode), {movecaret: true}); //isDirty = true; sandbox.publish('contentChanged'); }, @@ -119,7 +136,7 @@ return function(sandbox) { newNode.before(prefix); newNode.after(suffix); - this.selectNode(new wlxmlNode.Node(newNode), {moveCarret: true}); + this.selectNode(new wlxmlNode.Node(newNode), {movecaret: true}); //isDirty = true; sandbox.publish('contentChanged'); } @@ -146,7 +163,7 @@ return function(sandbox) { newNode.before(prefixNode); newNode.after(suffixNode); - this.selectNode(new wlxmlNode.Node(newNode), {moveCarret: true}); + this.selectNode(new wlxmlNode.Node(newNode), {movecaret: true}); //isDirty = true; sandbox.publish('contentChanged'); } @@ -166,8 +183,8 @@ return function(sandbox) { this.node.find('.rng-module-documentCanvas-currentNode').removeClass('rng-module-documentCanvas-currentNode'); nodeElement.addClass('rng-module-documentCanvas-currentNode'); - if(options.moveCarret) { - this.moveCarretToNode(nodeElement); + if(options.movecaret) { + this.movecaretToNode(nodeElement); } this.currentNode = wlxmlNode; @@ -201,7 +218,7 @@ return function(sandbox) { else { node = this.node.find('[wlxml-class|="p"]') } - this.selectNode(new wlxmlNode.Node(node), {moveCarret: true}); + this.selectNode(new wlxmlNode.Node(node), {movecaret: true}); }, toggleGrid: function(toggle) { this.node.find('[wlxml-tag]').toggleClass('rng-common-hoveredNode', toggle); @@ -210,7 +227,7 @@ return function(sandbox) { getNodeElement: function(wlxmlNode) { return this.node.find('#'+wlxmlNode.id); }, - moveCarretToNode: function(nodeElement) { + movecaretToNode: function(nodeElement) { var range = document.createRange(); range.selectNodeContents(nodeElement[0]); range.collapse(false); @@ -225,7 +242,9 @@ return function(sandbox) { /* public api */ return { start: function() { sandbox.publish('ready'); }, - getView: function() { return view.node; }, + getView: function() { + return view.node; + }, setDocument: function(xml) { var transformed = transformations.fromXML.getDocumentDescription(xml); view.setBody(transformed.HTMLTree); @@ -248,7 +267,7 @@ return function(sandbox) { }, selectNode: function(wlxmlNode) { if(!wlxmlNode.is(view.currentNode)) - view.selectNode(wlxmlNode, {moveCarret: true}); + view.selectNode(wlxmlNode, {movecaret: true}); }, toggleGrid: function(toggle) { view.toggleGrid(toggle);