From 8f2b5f13ac74ab18a0c2bac0e2d8209a40ce3c1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 17 Jul 2013 14:51:58 +0200 Subject: [PATCH] Setting caret after creating list --- modules/documentCanvas/canvas/canvas.js | 11 +++++++++++ modules/documentCanvas/commands.js | 2 ++ 2 files changed, 13 insertions(+) diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index c2b579b..7143b79 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -434,6 +434,9 @@ $.extend(Cursor.prototype, { getSelectionAnchor: function() { return this.getSelectionBoundry('anchor'); }, + getSelectionFocus: function() { + return this.getSelectionBoundry('focus'); + }, getSelectionBoundry: function(which) { var selection = window.getSelection(), anchorElement = this.canvas.getDocumentElement(selection.anchorNode), @@ -450,6 +453,14 @@ $.extend(Cursor.prototype, { offsetAtEnd: anchorElement && anchorElement.getText().length === selection.anchorOffset }; } + if(which === 'focus') { + return { + element: focusElement, + offset: selection.focusOffset, + offsetAtBeginning: selection.focusOffset === 0, + offsetAtEnd: focusElement && focusElement.getText().length === selection.focusOffset + }; + } var element, offset; diff --git a/modules/documentCanvas/commands.js b/modules/documentCanvas/commands.js index 96b7c70..b0fb093 100644 --- a/modules/documentCanvas/commands.js +++ b/modules/documentCanvas/commands.js @@ -56,7 +56,9 @@ commands.register('toggle-list', function(canvas, params) { parent2 = selectionEnd.element.parent() || undefined; if(params.toggle) { + var selectionFocus = cursor.getSelectionFocus(); canvas.list.create({element1: parent1, element2: parent2}); + canvas.setCurrentElement(selectionFocus.element, {caretTo: selectionFocus.offset}); } else { if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) { canvas.list.extractItems({element1: parent1, element2: parent2, merge: false}); -- 2.20.1