From b5fab6c09bccfcdd09ed63f6fddfab6486d1d919 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 8 Aug 2013 10:01:15 +0200 Subject: [PATCH] Simplifying toolbar list button Now it doesn't have a state and works in out of list context only --- modules/documentCanvas/canvas/documentElement.js | 6 ++++++ modules/documentCanvas/commands.js | 14 +++++++------- modules/documentToolbar/template.html | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) 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 @@
- +
-- 2.20.1