From f5625d9169ab5abd74846f127131decf29fb7fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Thu, 14 Mar 2019 11:58:41 +0100 Subject: [PATCH 01/24] Allow SHIFT keystrokes to be passed to other listeners alongside ALT and CTRL. --- plugins/widget/plugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index a0d7e36cd20..f62304ad42b 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -3574,9 +3574,9 @@ } else if ( keyCode == CKEDITOR.CTRL + 67 || keyCode == CKEDITOR.CTRL + 88 ) { copySingleWidget( widget, keyCode == CKEDITOR.CTRL + 88 ); return; // Do not preventDefault. - } else if ( keyCode in keystrokesNotBlockedByWidget || ( CKEDITOR.CTRL & keyCode ) || ( CKEDITOR.ALT & keyCode ) ) { + } else if ( keyCode in keystrokesNotBlockedByWidget || ( CKEDITOR.CTRL & keyCode ) || ( CKEDITOR.ALT & keyCode ) || ( CKEDITOR.SHIFT & keyCode ) ) { // Pass chosen keystrokes to other plugins or default fake sel handlers. - // Pass all CTRL/ALT keystrokes. + // Pass all CTRL/ALT/SHIFT keystrokes. return; } From be7ba03038ef7db29e93e412269cb91962e95fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Thu, 14 Mar 2019 12:31:44 +0100 Subject: [PATCH 02/24] Add manual tests. --- .../widget/manual/contextmenushortcuts.html | 10 ++++++++++ .../plugins/widget/manual/contextmenushortcuts.md | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/plugins/widget/manual/contextmenushortcuts.html create mode 100644 tests/plugins/widget/manual/contextmenushortcuts.md diff --git a/tests/plugins/widget/manual/contextmenushortcuts.html b/tests/plugins/widget/manual/contextmenushortcuts.html new file mode 100644 index 00000000000..780a6466021 --- /dev/null +++ b/tests/plugins/widget/manual/contextmenushortcuts.html @@ -0,0 +1,10 @@ +
+

\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)

+
+ + diff --git a/tests/plugins/widget/manual/contextmenushortcuts.md b/tests/plugins/widget/manual/contextmenushortcuts.md new file mode 100644 index 00000000000..5a4770f03f7 --- /dev/null +++ b/tests/plugins/widget/manual/contextmenushortcuts.md @@ -0,0 +1,15 @@ +@bender-tags: 4.11.4, bug, 1901, widget, accessibility +@bender-ui: collapsed +@bender-ckeditor-plugins: widget, wysiwygarea, contextmenu + +## Keyboard shortcuts for widgets' context menu + +### Scenario 1: `SHIFT + F10` + +1. Select widget in editor by left-click. +1. Press `SHIFT + F10`. **Expected:** Custom CKEditor contect menu opens. + +### Scenario 2: `CTRL + SHIFT + F10` + +1. Select widget in editor by left-click. +1. Press `CTRL + SHIFT + F10`. **Expected:** Custom CKEditor contect menu opens. From 10d4576f07ce776ba1a615879799d32d4f0e1882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Fri, 15 Mar 2019 14:03:06 +0100 Subject: [PATCH 03/24] Change widget in use from Mathjax to Placeholder for simplification. --- tests/plugins/widget/manual/contextmenushortcuts.html | 7 ++----- tests/plugins/widget/manual/contextmenushortcuts.md | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/plugins/widget/manual/contextmenushortcuts.html b/tests/plugins/widget/manual/contextmenushortcuts.html index 780a6466021..f2c85e26c5f 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.html +++ b/tests/plugins/widget/manual/contextmenushortcuts.html @@ -1,10 +1,7 @@
-

\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)

+

[[Focus me!]]

diff --git a/tests/plugins/widget/manual/contextmenushortcuts.md b/tests/plugins/widget/manual/contextmenushortcuts.md index 5a4770f03f7..6a5e2e97f34 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.md +++ b/tests/plugins/widget/manual/contextmenushortcuts.md @@ -1,6 +1,6 @@ @bender-tags: 4.11.4, bug, 1901, widget, accessibility @bender-ui: collapsed -@bender-ckeditor-plugins: widget, wysiwygarea, contextmenu +@bender-ckeditor-plugins: widget, wysiwygarea, contextmenu, placeholder ## Keyboard shortcuts for widgets' context menu From 9cbe07410b1385705fe7c3d71aaeceeb6812a95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Fri, 15 Mar 2019 14:05:21 +0100 Subject: [PATCH 04/24] Simplify instruction in test scenarios and remove spelling errors. --- tests/plugins/widget/manual/contextmenushortcuts.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/plugins/widget/manual/contextmenushortcuts.md b/tests/plugins/widget/manual/contextmenushortcuts.md index 6a5e2e97f34..bd1debf84c8 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.md +++ b/tests/plugins/widget/manual/contextmenushortcuts.md @@ -6,10 +6,10 @@ ### Scenario 1: `SHIFT + F10` -1. Select widget in editor by left-click. -1. Press `SHIFT + F10`. **Expected:** Custom CKEditor contect menu opens. +1. Focus widget in editor. +1. Press `SHIFT + F10`. **Expected:** Custom CKEditor context menu opens. ### Scenario 2: `CTRL + SHIFT + F10` -1. Select widget in editor by left-click. -1. Press `CTRL + SHIFT + F10`. **Expected:** Custom CKEditor contect menu opens. +1. Focus widget in editor. +1. Press `CTRL + SHIFT + F10`. **Expected:** Custom CKEditor context menu opens. From 4e938de4097ff060ea89d0d816c9d06979ccf84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Fri, 15 Mar 2019 14:14:19 +0100 Subject: [PATCH 05/24] Split long conditions line. --- plugins/widget/plugin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index f62304ad42b..e5ccef6f563 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -3574,7 +3574,10 @@ } else if ( keyCode == CKEDITOR.CTRL + 67 || keyCode == CKEDITOR.CTRL + 88 ) { copySingleWidget( widget, keyCode == CKEDITOR.CTRL + 88 ); return; // Do not preventDefault. - } else if ( keyCode in keystrokesNotBlockedByWidget || ( CKEDITOR.CTRL & keyCode ) || ( CKEDITOR.ALT & keyCode ) || ( CKEDITOR.SHIFT & keyCode ) ) { + } else if ( keyCode in keystrokesNotBlockedByWidget || + ( CKEDITOR.CTRL & keyCode ) || + ( CKEDITOR.ALT & keyCode ) || + ( CKEDITOR.SHIFT & keyCode ) ) { // Pass chosen keystrokes to other plugins or default fake sel handlers. // Pass all CTRL/ALT/SHIFT keystrokes. return; From 3a146dd45cd05221ba4850bdd6e86021abf714ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Fri, 15 Mar 2019 14:22:41 +0100 Subject: [PATCH 06/24] Add missing line feed at the end of file. --- tests/plugins/widget/contextmenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index 15cb41ba633..079a5b858a3 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -127,4 +127,4 @@ } ); } } ); -} )(); \ No newline at end of file +} )(); From f43caf272f7590006597cdf09dda69a50db18066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Fri, 15 Mar 2019 15:06:59 +0100 Subject: [PATCH 07/24] Add unit tests. --- tests/plugins/widget/contextmenu.js | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index 079a5b858a3..8d33a2428c4 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -22,6 +22,38 @@ var getWidgetById = widgetTestsTools.getWidgetById; bender.test( { + 'test SHIFT + F10 shortcut upon widget focus': function() { + var editor = this.editor; + + editor.widgets.add( 'testevent', { + editables: { + foo: '.foo' + } + } ); + + this.editorBot.setData( '

foo

foo

', function() { + var widget = getWidgetById( editor, 'w1' ); + widget.focus(); + assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.SHIFT + 121 } ) ); + } ); + }, + + 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { + var editor = this.editor; + + editor.widgets.add( 'testevent', { + editables: { + foo: '.foo' + } + } ); + + this.editorBot.setData( '

foo

foo

', function() { + var widget = getWidgetById( editor, 'w1' ); + widget.focus(); + assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); + } ); + }, + 'test contextMenu event firing': function() { var editor = this.editor; From 70458b0219425d5386434a24ad82b13438177ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 25 Mar 2019 13:46:46 +0100 Subject: [PATCH 08/24] Move comment to the right place. --- plugins/widget/plugin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index e5ccef6f563..e787f29456d 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -3570,16 +3570,16 @@ // ENTER. if ( keyCode == 13 ) { widget.edit(); - // CTRL+C or CTRL+X. + // CTRL+C or CTRL+X. } else if ( keyCode == CKEDITOR.CTRL + 67 || keyCode == CKEDITOR.CTRL + 88 ) { copySingleWidget( widget, keyCode == CKEDITOR.CTRL + 88 ); return; // Do not preventDefault. + // Pass chosen keystrokes to other plugins or default fake sel handlers. + // Pass all CTRL/ALT/SHIFT keystrokes. } else if ( keyCode in keystrokesNotBlockedByWidget || ( CKEDITOR.CTRL & keyCode ) || ( CKEDITOR.ALT & keyCode ) || ( CKEDITOR.SHIFT & keyCode ) ) { - // Pass chosen keystrokes to other plugins or default fake sel handlers. - // Pass all CTRL/ALT/SHIFT keystrokes. return; } From ac49397d9fd48808464515fe546a2a6d977c70f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 25 Mar 2019 13:51:09 +0100 Subject: [PATCH 09/24] Add ticket references. --- tests/plugins/widget/contextmenu.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index 8d33a2428c4..fe6dd3f4d6e 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -22,6 +22,7 @@ var getWidgetById = widgetTestsTools.getWidgetById; bender.test( { + // #1901 'test SHIFT + F10 shortcut upon widget focus': function() { var editor = this.editor; @@ -38,6 +39,7 @@ } ); }, + // #1901 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { var editor = this.editor; From 362909573d50660a73546f1742a928abe90099ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 25 Mar 2019 14:51:11 +0100 Subject: [PATCH 10/24] Move tests to appropriate file. --- tests/plugins/widget/contextmenu.js | 33 --------------------- tests/plugins/widget/widgetsintegration.js | 34 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index fe6dd3f4d6e..1000010987a 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -22,39 +22,6 @@ var getWidgetById = widgetTestsTools.getWidgetById; bender.test( { - // #1901 - 'test SHIFT + F10 shortcut upon widget focus': function() { - var editor = this.editor; - - editor.widgets.add( 'testevent', { - editables: { - foo: '.foo' - } - } ); - - this.editorBot.setData( '

foo

foo

', function() { - var widget = getWidgetById( editor, 'w1' ); - widget.focus(); - assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.SHIFT + 121 } ) ); - } ); - }, - - // #1901 - 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { - var editor = this.editor; - - editor.widgets.add( 'testevent', { - editables: { - foo: '.foo' - } - } ); - - this.editorBot.setData( '

foo

foo

', function() { - var widget = getWidgetById( editor, 'w1' ); - widget.focus(); - assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); - } ); - }, 'test contextMenu event firing': function() { var editor = this.editor; diff --git a/tests/plugins/widget/widgetsintegration.js b/tests/plugins/widget/widgetsintegration.js index a4f17ff1150..e9f787bdbe5 100644 --- a/tests/plugins/widget/widgetsintegration.js +++ b/tests/plugins/widget/widgetsintegration.js @@ -57,6 +57,40 @@ this.editor.setReadOnly( false ); }, + // #1901 + 'test SHIFT + F10 shortcut upon widget focus': function() { + var editor = this.editor; + + editor.widgets.add( 'testevent', { + editables: { + foo: '.foo' + } + } ); + + this.editorBot.setData( '

foo

foo

', function() { + var widget = getWidgetById( editor, 'w1' ); + widget.focus(); + assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.SHIFT + 121 } ) ); + } ); + }, + + // #1901 + 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { + var editor = this.editor; + + editor.widgets.add( 'testevent', { + editables: { + foo: '.foo' + } + } ); + + this.editorBot.setData( '

foo

foo

', function() { + var widget = getWidgetById( editor, 'w1' ); + widget.focus(); + assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); + } ); + }, + 'test initializing widgets': function() { var editor = this.editor; From 799fec01f84028525a13fd988157ce68111292a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 25 Mar 2019 18:58:50 +0100 Subject: [PATCH 11/24] Add tests for displaying context menu. --- tests/plugins/widget/contextmenu.js | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index 1000010987a..f8269255fba 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -22,6 +22,55 @@ var getWidgetById = widgetTestsTools.getWidgetById; bender.test( { + // #1901 + 'test SHIFT + F10 shortcut upon widget focus': function() { + var editor = this.editor; + + editor.widgets.add( 'testevent', { + editables: { + foo: '.foo' + } + } ); + + this.editorBot.setData( + '

foo

foo

', + function() { + var w1 = getWidgetById( editor, 'w1' ), + opened = 0; + w1.on( 'contextMenu', function() { + opened += 1; + } ); + w1.focus(); + editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.SHIFT + 121 } ) ); + assert.areSame( opened, 1, 'context menu did not open' ); + } + ); + }, + + // #1901 + 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { + var editor = this.editor; + + editor.widgets.add( 'testevent', { + editables: { + foo: '.foo' + } + } ); + + this.editorBot.setData( + '

foo

foo

', + function() { + var w1 = getWidgetById( editor, 'w1' ), + opened = 0; + w1.on( 'contextMenu', function() { + opened += 1; + } ); + w1.focus(); + editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); + assert.areSame( opened, 1, 'context menu did not open' ); + } + ); + }, 'test contextMenu event firing': function() { var editor = this.editor; From c7a1a7ae73a2c991a57fdaa59fda5b5c54c77b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20Bogda=C5=84ski?= Date: Tue, 26 Mar 2019 10:27:14 +0100 Subject: [PATCH 12/24] Update changelog entry. Co-Authored-By: Dumluregn --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 6f7a049d2e1..08a08c045bb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Fixed Issues: * [#2816](https://github.com/ckeditor/ckeditor-dev/issues/2816): Fixed: [Enhanced Image](https://ckeditor.com/cke4/addon/image2) resize handler is visible in [read-only mode](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html). * [#2874](https://github.com/ckeditor/ckeditor-dev/issues/2874): Fixed: [Enhanced Image](https://ckeditor.com/cke4/addon/image2) resize handler is not added when editor is initialized in [read-only mode](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html). * [#2775](https://github.com/ckeditor/ckeditor-dev/issues/2775): Fixed: [Clipboard](https://ckeditor.com/cke4/addon/clipboard) paste buttons have wrong state when [read-only](https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html) mode is set by mouse event listener with [Div Editing Area](https://ckeditor.com/cke4/addon/divarea) plugin. +* [#1901](https://github.com/ckeditor/ckeditor-dev/issues/1901): Fixed: Can't open a context menu with keyboard shortcut Shift+F10 over a [Widget](https://ckeditor.com/cke4/addon/widget). ## CKEditor 4.11.3 From 733acc4d0d8f242c36b702931edcdd93a72871cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Tue, 26 Mar 2019 10:17:38 +0100 Subject: [PATCH 13/24] Put ticket references into brackets. --- tests/plugins/widget/contextmenu.js | 4 ++-- tests/plugins/widget/widgetsintegration.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index f8269255fba..dd3cffdd531 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -22,7 +22,7 @@ var getWidgetById = widgetTestsTools.getWidgetById; bender.test( { - // #1901 + // (#1901) 'test SHIFT + F10 shortcut upon widget focus': function() { var editor = this.editor; @@ -47,7 +47,7 @@ ); }, - // #1901 + // (#1901) 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { var editor = this.editor; diff --git a/tests/plugins/widget/widgetsintegration.js b/tests/plugins/widget/widgetsintegration.js index e9f787bdbe5..96252270800 100644 --- a/tests/plugins/widget/widgetsintegration.js +++ b/tests/plugins/widget/widgetsintegration.js @@ -57,7 +57,7 @@ this.editor.setReadOnly( false ); }, - // #1901 + // (#1901) 'test SHIFT + F10 shortcut upon widget focus': function() { var editor = this.editor; @@ -74,7 +74,7 @@ } ); }, - // #1901 + // (#1901) 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { var editor = this.editor; From 5585540a1777b624bf2c78205f7229d4f82fe41f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Tue, 26 Mar 2019 10:20:26 +0100 Subject: [PATCH 14/24] Replace variable name with more meaningful one. --- tests/plugins/widget/contextmenu.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index dd3cffdd531..0a49aaa3803 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -35,12 +35,12 @@ this.editorBot.setData( '

foo

foo

', function() { - var w1 = getWidgetById( editor, 'w1' ), + var widget = getWidgetById( editor, 'w1' ), opened = 0; - w1.on( 'contextMenu', function() { + widget.on( 'contextMenu', function() { opened += 1; } ); - w1.focus(); + widget.focus(); editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.SHIFT + 121 } ) ); assert.areSame( opened, 1, 'context menu did not open' ); } From 871a5d99548a120b3537aa8fdf9f18f2772e8de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Tue, 26 Mar 2019 10:25:34 +0100 Subject: [PATCH 15/24] Simplify code using sinon.js library. --- tests/plugins/widget/contextmenu.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index 0a49aaa3803..155869e64bc 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -36,13 +36,11 @@ '

foo

foo

', function() { var widget = getWidgetById( editor, 'w1' ), - opened = 0; - widget.on( 'contextMenu', function() { - opened += 1; - } ); + spy = sinon.spy(); + widget.on( 'contextMenu', spy ); widget.focus(); editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.SHIFT + 121 } ) ); - assert.areSame( opened, 1, 'context menu did not open' ); + assert.isTrue( spy.calledOnce ); } ); }, @@ -60,14 +58,12 @@ this.editorBot.setData( '

foo

foo

', function() { - var w1 = getWidgetById( editor, 'w1' ), - opened = 0; - w1.on( 'contextMenu', function() { - opened += 1; - } ); - w1.focus(); + var widget = getWidgetById( editor, 'w1' ), + spy = sinon.spy(); + widget.on( 'contextMenu', spy ); + widget.focus(); editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); - assert.areSame( opened, 1, 'context menu did not open' ); + assert.isTrue( spy.calledOnce ); } ); }, From 66e415a5a8bf2c00f680958437014f694568f8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Tue, 26 Mar 2019 10:32:14 +0100 Subject: [PATCH 16/24] Add breaking lines for readability and change assertion method for better fit. --- tests/plugins/widget/contextmenu.js | 4 ++++ tests/plugins/widget/widgetsintegration.js | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index 155869e64bc..141e13096b8 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -38,8 +38,10 @@ var widget = getWidgetById( editor, 'w1' ), spy = sinon.spy(); widget.on( 'contextMenu', spy ); + widget.focus(); editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.SHIFT + 121 } ) ); + assert.isTrue( spy.calledOnce ); } ); @@ -61,8 +63,10 @@ var widget = getWidgetById( editor, 'w1' ), spy = sinon.spy(); widget.on( 'contextMenu', spy ); + widget.focus(); editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); + assert.isTrue( spy.calledOnce ); } ); diff --git a/tests/plugins/widget/widgetsintegration.js b/tests/plugins/widget/widgetsintegration.js index 96252270800..1d36e992146 100644 --- a/tests/plugins/widget/widgetsintegration.js +++ b/tests/plugins/widget/widgetsintegration.js @@ -69,8 +69,9 @@ this.editorBot.setData( '

foo

foo

', function() { var widget = getWidgetById( editor, 'w1' ); + widget.focus(); - assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.SHIFT + 121 } ) ); + assert.isNotNull( widget.fire( 'key', { keyCode: CKEDITOR.SHIFT + 121 } ) ); } ); }, @@ -86,8 +87,9 @@ this.editorBot.setData( '

foo

foo

', function() { var widget = getWidgetById( editor, 'w1' ); + widget.focus(); - assert.isObject( widget.fire( 'key', { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); + assert.isNotNull( widget.fire( 'key', { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); } ); }, From 8a026ea8a6889dbf3ec978ff9191fc57975b1a1d Mon Sep 17 00:00:00 2001 From: Jacek Bogdanski Date: Wed, 27 Mar 2019 11:58:27 +0100 Subject: [PATCH 17/24] Updated unit test to be more generic. --- tests/plugins/widget/widgetsintegration.js | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/tests/plugins/widget/widgetsintegration.js b/tests/plugins/widget/widgetsintegration.js index 1d36e992146..d9cce35c99f 100644 --- a/tests/plugins/widget/widgetsintegration.js +++ b/tests/plugins/widget/widgetsintegration.js @@ -58,7 +58,7 @@ }, // (#1901) - 'test SHIFT + F10 shortcut upon widget focus': function() { + 'test modifier keystrokes upon widget focus': function() { var editor = this.editor; editor.widgets.add( 'testevent', { @@ -71,25 +71,13 @@ var widget = getWidgetById( editor, 'w1' ); widget.focus(); - assert.isNotNull( widget.fire( 'key', { keyCode: CKEDITOR.SHIFT + 121 } ) ); - } ); - }, - - // (#1901) - 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { - var editor = this.editor; - - editor.widgets.add( 'testevent', { - editables: { - foo: '.foo' - } - } ); + assert.areNotEqual( false, widget.fire( 'key', { keyCode: CKEDITOR.SHIFT + 121 } ), 'Shift should not be canceled' ); // SHIFT + F10 - this.editorBot.setData( '

foo

foo

', function() { - var widget = getWidgetById( editor, 'w1' ); + widget.focus(); + assert.areNotEqual( false, widget.fire( 'key', { keyCode: CKEDITOR.CTRL + 121 } ), 'Ctrl should not be canceled' ); // CTRL + F10 widget.focus(); - assert.isNotNull( widget.fire( 'key', { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); + assert.areNotEqual( false, widget.fire( 'key', { keyCode: CKEDITOR.ALT + 121 } ), 'Alt should not be canceled' ); // ALT + F10 } ); }, From 18f9a3af562fba03368bf3e665cc44b80b079cdb Mon Sep 17 00:00:00 2001 From: Jacek Bogdanski Date: Wed, 27 Mar 2019 13:26:17 +0100 Subject: [PATCH 18/24] Small refactoring. --- tests/plugins/widget/contextmenu.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/plugins/widget/contextmenu.js b/tests/plugins/widget/contextmenu.js index 141e13096b8..650864aa357 100644 --- a/tests/plugins/widget/contextmenu.js +++ b/tests/plugins/widget/contextmenu.js @@ -37,9 +37,10 @@ function() { var widget = getWidgetById( editor, 'w1' ), spy = sinon.spy(); - widget.on( 'contextMenu', spy ); + widget.on( 'contextMenu', spy ); widget.focus(); + editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.SHIFT + 121 } ) ); assert.isTrue( spy.calledOnce ); @@ -47,7 +48,6 @@ ); }, - // (#1901) 'test CTRL + SHIFT + F10 shortcut upon widget focus': function() { var editor = this.editor; @@ -62,9 +62,10 @@ function() { var widget = getWidgetById( editor, 'w1' ), spy = sinon.spy(); - widget.on( 'contextMenu', spy ); + widget.on( 'contextMenu', spy ); widget.focus(); + editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 } ) ); assert.isTrue( spy.calledOnce ); From 381c44589a767150c51cced188a0170ea0557497 Mon Sep 17 00:00:00 2001 From: Jacek Bogdanski Date: Wed, 27 Mar 2019 13:30:43 +0100 Subject: [PATCH 19/24] Small manual test readibility improvement. --- tests/plugins/widget/manual/contextmenushortcuts.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/plugins/widget/manual/contextmenushortcuts.md b/tests/plugins/widget/manual/contextmenushortcuts.md index bd1debf84c8..86cd7315b4d 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.md +++ b/tests/plugins/widget/manual/contextmenushortcuts.md @@ -7,9 +7,13 @@ ### Scenario 1: `SHIFT + F10` 1. Focus widget in editor. -1. Press `SHIFT + F10`. **Expected:** Custom CKEditor context menu opens. +1. Press `SHIFT + F10`. + +**Expected:** Custom CKEditor context menu opens. ### Scenario 2: `CTRL + SHIFT + F10` 1. Focus widget in editor. -1. Press `CTRL + SHIFT + F10`. **Expected:** Custom CKEditor context menu opens. +1. Press `CTRL + SHIFT + F10`. + +**Expected:** Custom CKEditor context menu opens. From 4d3a8a1567109bfd37d47ebfcee0e233085e4a2d Mon Sep 17 00:00:00 2001 From: Jacek Bogdanski Date: Wed, 27 Mar 2019 13:36:13 +0100 Subject: [PATCH 20/24] Updated manual test description. --- tests/plugins/widget/manual/contextmenushortcuts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/plugins/widget/manual/contextmenushortcuts.md b/tests/plugins/widget/manual/contextmenushortcuts.md index 86cd7315b4d..8991414268c 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.md +++ b/tests/plugins/widget/manual/contextmenushortcuts.md @@ -9,11 +9,11 @@ 1. Focus widget in editor. 1. Press `SHIFT + F10`. -**Expected:** Custom CKEditor context menu opens. +**Expected:** Context menu opens. ### Scenario 2: `CTRL + SHIFT + F10` 1. Focus widget in editor. 1. Press `CTRL + SHIFT + F10`. -**Expected:** Custom CKEditor context menu opens. +**Expected:** Context menu opens. From 6f4fe399df1467e8d347218ec23f80a6df4578f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 1 Apr 2019 13:53:30 +0200 Subject: [PATCH 21/24] Remove unused variable declaration to fix jshint. --- plugins/widget/plugin.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index e787f29456d..c994857a4f0 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -3641,8 +3641,7 @@ function addCustomStyleHandler() { // Styles categorized by group. It is used to prevent applying styles for the same group being used together. - var styleGroups = {}, - styleDefinitions = []; + var styleGroups = {}; /** * The class representing a widget style. It is an {@link CKEDITOR#STYLE_OBJECT object} like From 9313845207571d4e9535186ab2d0c0ea10aa27d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 1 Apr 2019 13:57:23 +0200 Subject: [PATCH 22/24] Enable only SHIFT + F10 hotkey due to problems with other keyboard shortcuts for widgets. --- plugins/widget/plugin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index c994857a4f0..88757ceea6d 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -3575,11 +3575,11 @@ copySingleWidget( widget, keyCode == CKEDITOR.CTRL + 88 ); return; // Do not preventDefault. // Pass chosen keystrokes to other plugins or default fake sel handlers. - // Pass all CTRL/ALT/SHIFT keystrokes. + // Pass all CTRL/ALT and SHIFT + F10 keystrokes. } else if ( keyCode in keystrokesNotBlockedByWidget || + ( keyCode == CKEDITOR.SHIFT + 121 ) || ( CKEDITOR.CTRL & keyCode ) || - ( CKEDITOR.ALT & keyCode ) || - ( CKEDITOR.SHIFT & keyCode ) ) { + ( CKEDITOR.ALT & keyCode ) ) { return; } From 1355f27e96d05bbe815605d6ed948f12c3ca6ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 1 Apr 2019 13:59:33 +0200 Subject: [PATCH 23/24] Add manual tests for block widget and other keyboard shortcuts. --- .../widget/manual/contextmenushortcuts.html | 6 ++++ .../widget/manual/contextmenushortcuts.md | 28 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/plugins/widget/manual/contextmenushortcuts.html b/tests/plugins/widget/manual/contextmenushortcuts.html index f2c85e26c5f..a34cb7fa9c4 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.html +++ b/tests/plugins/widget/manual/contextmenushortcuts.html @@ -1,7 +1,13 @@

[[Focus me!]]

+
+
+		Hello world!
+	
+
diff --git a/tests/plugins/widget/manual/contextmenushortcuts.md b/tests/plugins/widget/manual/contextmenushortcuts.md index 8991414268c..3af5e11ef5f 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.md +++ b/tests/plugins/widget/manual/contextmenushortcuts.md @@ -1,9 +1,11 @@ @bender-tags: 4.11.4, bug, 1901, widget, accessibility @bender-ui: collapsed -@bender-ckeditor-plugins: widget, wysiwygarea, contextmenu, placeholder +@bender-ckeditor-plugins: widget, wysiwygarea, contextmenu, placeholder, codesnippet, enterkey, undo ## Keyboard shortcuts for widgets' context menu +Please do each test for both **inline** (first editor) and **block** (second editor) widget. + ### Scenario 1: `SHIFT + F10` 1. Focus widget in editor. @@ -17,3 +19,27 @@ 1. Press `CTRL + SHIFT + F10`. **Expected:** Context menu opens. + +### Scenario 3: `SHIFT + LEFT` + +1. Focus widget in editor. +1. Press `SHIFT + LEFT`. +1. Open console. + +**Expected:** There should be no error in console. + +### Scenario 4: `SHIFT + ENTER` + +1. Focus widget in editor. +1. Press `SHIFT + ENTER` twice. +1. Click `Undo` button. +1. Open console. + +**Expected:** New line should not be inserted and console should remain clean. + +### Scenario 5: `SHIFT + Tab` + +1. Focus widget in editor. +1. Press `SHIFT + TAB`. + +**Expected:** Widget should still be focused. From c01a48c0e51f3023f647e3eaa4e28658537d6df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarze=CC=A8bski?= Date: Mon, 1 Apr 2019 15:39:23 +0200 Subject: [PATCH 24/24] Change tests and solution basing on code review. --- plugins/widget/plugin.js | 6 ++++-- tests/plugins/widget/manual/contextmenushortcuts.html | 4 +++- tests/plugins/widget/manual/contextmenushortcuts.md | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js index 88757ceea6d..05c4a9f1f37 100644 --- a/plugins/widget/plugin.js +++ b/plugins/widget/plugin.js @@ -3104,6 +3104,9 @@ // LEFT, RIGHT, UP, DOWN, DEL, BACKSPACE - unblock default fake sel handlers. var keystrokesNotBlockedByWidget = { 37: 1, 38: 1, 39: 1, 40: 1, 8: 1, 46: 1 }; + // Do not block SHIFT + F10 which opens context menu (#1901). + keystrokesNotBlockedByWidget[ CKEDITOR.SHIFT + 121 ] = 1; + // Applies or removes style's classes from widget. // @param {CKEDITOR.style} style Custom widget style. // @param {Boolean} apply Whether to apply or remove style. @@ -3575,9 +3578,8 @@ copySingleWidget( widget, keyCode == CKEDITOR.CTRL + 88 ); return; // Do not preventDefault. // Pass chosen keystrokes to other plugins or default fake sel handlers. - // Pass all CTRL/ALT and SHIFT + F10 keystrokes. + // Pass all CTRL/ALT keystrokes. } else if ( keyCode in keystrokesNotBlockedByWidget || - ( keyCode == CKEDITOR.SHIFT + 121 ) || ( CKEDITOR.CTRL & keyCode ) || ( CKEDITOR.ALT & keyCode ) ) { return; diff --git a/tests/plugins/widget/manual/contextmenushortcuts.html b/tests/plugins/widget/manual/contextmenushortcuts.html index a34cb7fa9c4..6118f9843f3 100644 --- a/tests/plugins/widget/manual/contextmenushortcuts.html +++ b/tests/plugins/widget/manual/contextmenushortcuts.html @@ -1,10 +1,12 @@
-

[[Focus me!]]

+

Foo [[Focus me!]] Bar

+

Foo

 		Hello world!
 	
+

Bar