From 1a423db9da1ee3de2be20da5a03b6dac84f5441a Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 29 Nov 2017 14:11:06 +0100 Subject: [PATCH 1/8] Tests: added unit tests for options.cssSelector not matched in case of fully selected image/link. --- .../balloontoolbar/context/cssselector.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/plugins/balloontoolbar/context/cssselector.js b/tests/plugins/balloontoolbar/context/cssselector.js index a0b49b803bb..7b7b395e54c 100644 --- a/tests/plugins/balloontoolbar/context/cssselector.js +++ b/tests/plugins/balloontoolbar/context/cssselector.js @@ -88,6 +88,22 @@ contextTools._assertToolbarVisible( false, context ); }, + 'test matching images': function() { + var context = this._getContextStub( 'img' ); + + this.editorBot.setHtmlWithSelection( '

foo [] bar

' ); + + contextTools._assertToolbarVisible( true, context ); + }, + + 'test matching link': function() { + var context = this._getContextStub( 'a' ); + + this.editorBot.setHtmlWithSelection( '

foo [bar] baz

' ); + + contextTools._assertToolbarVisible( true, context ); + }, + /* * @param {String} selector A selector to be used as `options.elements`. * @returns {CKEDITOR.plugins.balloontoolbar.context} Context instance with `selector` used as a CSS selector. From 7165f5d96014ce72d888d7cff8e074b6db1384d0 Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 29 Nov 2017 14:16:06 +0100 Subject: [PATCH 2/8] Fixed the case where fully selected link/image would not trigger Balloon Toolbar context. --- plugins/balloontoolbar/plugin.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/balloontoolbar/plugin.js b/plugins/balloontoolbar/plugin.js index e95da97f12c..207db6ec14b 100644 --- a/plugins/balloontoolbar/plugin.js +++ b/plugins/balloontoolbar/plugin.js @@ -468,6 +468,12 @@ // Match element selectors. if ( path ) { + var selectedElem = selection.getSelectedElement(); + + if ( selectedElem && !selectedElem.isReadOnly() ) { + matchEachContext( this._contexts, elementsMatcher, selectedElem ); + } + for ( var i = 0; i < path.elements.length; i++ ) { var curElement = path.elements[ i ]; // Skip non-editable elements (e.g. widget internal structure). From e8c44fed9677da5fe61e035f7210a7889ad7d25b Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 29 Nov 2017 14:34:12 +0100 Subject: [PATCH 3/8] Referenced original issue. --- tests/plugins/balloontoolbar/context/cssselector.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/plugins/balloontoolbar/context/cssselector.js b/tests/plugins/balloontoolbar/context/cssselector.js index 7b7b395e54c..71ece4c067d 100644 --- a/tests/plugins/balloontoolbar/context/cssselector.js +++ b/tests/plugins/balloontoolbar/context/cssselector.js @@ -88,6 +88,7 @@ contextTools._assertToolbarVisible( false, context ); }, + // #1274 'test matching images': function() { var context = this._getContextStub( 'img' ); From 5ca2c22e3c48e9c9b23f4e016a278a129f320e4f Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 29 Nov 2017 14:41:30 +0100 Subject: [PATCH 4/8] Tests: added a manual test for matching image using cssSelector in the Balloon Toolbar. --- .../context/manual/imgselect.html | 45 +++++++++++++++++++ .../context/manual/imgselect.md | 15 +++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/plugins/balloontoolbar/context/manual/imgselect.html create mode 100644 tests/plugins/balloontoolbar/context/manual/imgselect.md diff --git a/tests/plugins/balloontoolbar/context/manual/imgselect.html b/tests/plugins/balloontoolbar/context/manual/imgselect.html new file mode 100644 index 00000000000..42115dc7e44 --- /dev/null +++ b/tests/plugins/balloontoolbar/context/manual/imgselect.html @@ -0,0 +1,45 @@ + + + + +
+

Sample image:

+ + Sample image +
+ + diff --git a/tests/plugins/balloontoolbar/context/manual/imgselect.md b/tests/plugins/balloontoolbar/context/manual/imgselect.md new file mode 100644 index 00000000000..f74c506d9e0 --- /dev/null +++ b/tests/plugins/balloontoolbar/context/manual/imgselect.md @@ -0,0 +1,15 @@ +@bender-ui: collapsed +@bender-tags: 4.8.1, bug, balloontoolbar, 1274 +@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, floatingspace, balloontoolbar, sourcearea, link, elementspath, image + +# Image Selection + +1. Select an image. + +## Expected + +Toolbar is shown. + +## Unexpected + +No toolbar is visible. \ No newline at end of file From 15cf73ccb6e654858daa8b86802a5acb3830d85c Mon Sep 17 00:00:00 2001 From: Marek Lewandowski Date: Wed, 27 Dec 2017 17:00:56 +0100 Subject: [PATCH 5/8] Corrected tests, added more docs to the code. --- plugins/balloontoolbar/plugin.js | 2 ++ .../balloontoolbar/context/manual/imgselect.html | 10 ---------- .../plugins/balloontoolbar/context/manual/imgselect.md | 4 ++-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/plugins/balloontoolbar/plugin.js b/plugins/balloontoolbar/plugin.js index 207db6ec14b..6e721251cfe 100644 --- a/plugins/balloontoolbar/plugin.js +++ b/plugins/balloontoolbar/plugin.js @@ -468,6 +468,8 @@ // Match element selectors. if ( path ) { + // First check the outermost element (if any was selected), since the selection got shrinked + // it would be otherwise skipped (#1274). var selectedElem = selection.getSelectedElement(); if ( selectedElem && !selectedElem.isReadOnly() ) { diff --git a/tests/plugins/balloontoolbar/context/manual/imgselect.html b/tests/plugins/balloontoolbar/context/manual/imgselect.html index 42115dc7e44..89ce1bfe2df 100644 --- a/tests/plugins/balloontoolbar/context/manual/imgselect.html +++ b/tests/plugins/balloontoolbar/context/manual/imgselect.html @@ -1,12 +1,3 @@ - -