From: Aleksander Ɓukasz Date: Thu, 8 Aug 2013 08:01:15 +0000 (+0200) Subject: Simplifying toolbar list button X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/b5fab6c09bccfcdd09ed63f6fddfab6486d1d919?ds=sidebyside Simplifying toolbar list button Now it doesn't have a state and works in out of list context only --- diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 4d74722..1a2ef91 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -103,6 +103,12 @@ $.extend(DocumentElement.prototype, { isVisible: function() { return this instanceof DocumentTextElement || this.getWlxmlTag() !== 'metadata'; + }, + + isInsideList: function() { + return this.parents().some(function(parent) { + return parent.is('list'); + }); } }); diff --git a/modules/documentCanvas/commands.js b/modules/documentCanvas/commands.js index 8152ccd..738ab76 100644 --- a/modules/documentCanvas/commands.js +++ b/modules/documentCanvas/commands.js @@ -48,7 +48,7 @@ commands.register('wrap-node', function(canvas) { } }); -commands.register('toggle-list', function(canvas, params) { +commands.register('list', function(canvas, params) { var cursor = canvas.getCursor(), selectionStart = cursor.getSelectionStart(), selectionEnd = cursor.getSelectionEnd(), @@ -56,13 +56,13 @@ commands.register('toggle-list', function(canvas, params) { parent2 = selectionEnd.element.parent() || undefined; var selectionFocus = cursor.getSelectionFocus(); - if(params.toggle) { - canvas.list.create({element1: parent1, element2: parent2}); - } else { - if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) { - canvas.list.extractItems({element1: parent1, element2: parent2, merge: false}); - } + + if(selectionStart.element.isInsideList() || selectionEnd.element.isInsideList()) { + return; } + + canvas.list.create({element1: parent1, element2: parent2}); + canvas.setCurrentElement(selectionFocus.element, {caretTo: selectionFocus.offset}); }); diff --git a/modules/documentToolbar/template.html b/modules/documentToolbar/template.html index 86357bc..7701e5f 100644 --- a/modules/documentToolbar/template.html +++ b/modules/documentToolbar/template.html @@ -23,7 +23,7 @@
- +