From e669605bf75acf5d20b67ce6f9886e9259146615 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 13 May 2014 12:39:29 +0200 Subject: [PATCH 1/1] editor: plugins/core - restore selection after editing/deleting link via a link tool box --- src/editor/plugins/core/links/linkElement.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/editor/plugins/core/links/linkElement.js b/src/editor/plugins/core/links/linkElement.js index 503e958..8d280c7 100644 --- a/src/editor/plugins/core/links/linkElement.js +++ b/src/editor/plugins/core/links/linkElement.js @@ -40,6 +40,7 @@ _.extend(linkElement, { changeLink: function(e) { var el = this, doc = this.wlxmlNode.document, + offset = el.canvas.getSelection().toDocumentFragment().offset, dialog = Dialog.create({ title: gettext('Edit link'), executeButtonText: gettext('Apply'), @@ -63,6 +64,9 @@ _.extend(linkElement, { metadata: { description: gettext('Edit link'), fragment: doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:0}) + }, + success: function() { + el.canvas.select(doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:offset})); } }); }); @@ -74,11 +78,23 @@ _.extend(linkElement, { doc = this.wlxmlNode.document; el.wlxmlNode.document.transaction(function() { - el.wlxmlNode.unwrapContent(); + var f = el.canvas.getSelection().toDocumentFragment(), + prefLen = 0, + ret; + + if(el.wlxmlNode.isPrecededByTextNode()) { + prefLen = el.wlxmlNode.prev().getText().length; + } + + ret = el.wlxmlNode.unwrapContent(); + return doc.createFragment(doc.CaretFragment, {node: ret.element1, offset: prefLen + f.offset}); }, { metadata: { description: gettext('Remove link'), fragment: doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:0}) + }, + success: function(ret) { + el.canvas.select(ret); } }); }, -- 2.20.1