X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/2390a92e90ce831cf87c87c2c48b80f85c47fa99..c0e11a8f6d0d9a4c030aa90fe91f0fc49cd05e0e:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index bb4ad31..f3c0a5c 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -93,12 +93,27 @@ rng.modules.visualEditor = function(sandbox) { this.currentNode = node; mediator.nodeSelected(node); }, - markFirstSelected: function() { + selectNode: function(node) { + view._markSelected(node); + var range = document.createRange(); + range.selectNodeContents(node[0]); + range.collapse(false); + + var selection = document.getSelection(); + selection.removeAllRanges() + selection.addRange(range); + }, + selectFirstNode: function() { var firstNodeWithText = this.node.find('[wlxml-tag]').filter(function() { return $(this).clone().children().remove().end().text().trim() !== ''; }).first(); + var node; if(firstNodeWithText.length) - $(firstNodeWithText[0]).click().focus(); + node = $(firstNodeWithText[0]) + else { + node = this.node.find('[wlxml-class|="p"]') + } + this.selectNode(node); }, _addMetaRow: function(key, value) { var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''})); @@ -173,15 +188,7 @@ rng.modules.visualEditor = function(sandbox) { return view.currentNode; }, nodeCreated: function(node) { - view._markSelected(node); - - var range = document.createRange(); - range.selectNodeContents(node[0]); - range.collapse(false); - - var selection = document.getSelection(); - selection.removeAllRanges() - selection.addRange(range); + view.selectNode(node); }, nodeSelected: function(node) { @@ -218,7 +225,7 @@ rng.modules.visualEditor = function(sandbox) { onShowed: function() { if(!wasShownAlready) { wasShownAlready = true; - view.markFirstSelected(); + view.selectFirstNode(); } }