From f3f8aaa16b9c64a4b5845db0f90d31055f32292d Mon Sep 17 00:00:00 2001 From: Jacek Bogdanski Date: Thu, 26 Mar 2020 13:57:57 +0100 Subject: [PATCH 1/4] Fixed autocomplete navigation. --- plugins/autocomplete/plugin.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins/autocomplete/plugin.js b/plugins/autocomplete/plugin.js index a28800d037c..e9789d0b96b 100644 --- a/plugins/autocomplete/plugin.js +++ b/plugins/autocomplete/plugin.js @@ -288,26 +288,28 @@ this.viewRepositionListener(); }, this ) ); - this._listeners.push( editor.on( 'contentDom', onContentDom, this ) ); - // Don't let browser to focus dropdown element (#2107). this._listeners.push( this.view.element.on( 'mousedown', function( e ) { e.data.preventDefault(); }, null, null, 9999 ) ); - // Attach if editor is already initialized. + // Register keybindings if editor is already initialized. if ( editable ) { - onContentDom.call( this ); + this.registerPanelNavigation(); } - function onContentDom() { - // Priority 5 to get before the enterkey. - // Note: CKEditor's event system has a limitation that one function (in this case this.onKeyDown) - // cannot be used as listener for the same event more than once. Hence, wrapper function. - this._listeners.push( editable.on( 'keydown', function( evt ) { - this.onKeyDown( evt ); - }, this, null, 5 ) ); - } + editor.on( 'contentDom', this.registerPanelNavigation, this ); + }, + + registerPanelNavigation: function() { + var editable = this.editor.editable(); + + // Priority 5 to get before the enterkey. + // Note: CKEditor's event system has a limitation that one function (in this case this.onKeyDown) + // cannot be used as listener for the same event more than once. Hence, wrapper function. + this._listeners.push( editable.attachListener( editable, 'keydown', function( evt ) { + this.onKeyDown( evt ); + }, this, null, 5 ) ); }, /** From d76490b76cec1fa6da2851813c862a678bb09437 Mon Sep 17 00:00:00 2001 From: Jacek Bogdanski Date: Fri, 27 Mar 2020 09:30:05 +0100 Subject: [PATCH 2/4] Added tests coverage. --- tests/plugins/autocomplete/autocomplete.js | 33 ++++++++++++++++++- .../plugins/autocomplete/manual/navigation.md | 13 ++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/plugins/autocomplete/manual/navigation.md diff --git a/tests/plugins/autocomplete/autocomplete.js b/tests/plugins/autocomplete/autocomplete.js index 89cf87f5bab..ecc7ea12b7f 100644 --- a/tests/plugins/autocomplete/autocomplete.js +++ b/tests/plugins/autocomplete/autocomplete.js @@ -1,5 +1,5 @@ /* bender-tags: editor */ -/* bender-ckeditor-plugins: autocomplete,wysiwygarea */ +/* bender-ckeditor-plugins: autocomplete,wysiwygarea,sourcearea */ ( function() { 'use strict'; @@ -11,6 +11,11 @@ removePlugins: 'tab' } }, + source: { + config: { + removePlugins: 'tab' + } + }, arrayKeystrokes: { config: { autocomplete_commitKeystrokes: [ 16 ], // SHIFT @@ -157,6 +162,32 @@ wait(); }, + // (#3938) + 'test navigation keybindings are registered after changing mode': function() { + var editor = this.editors.source, + ac = new CKEDITOR.plugins.autocomplete( editor, configDefinition ); + + editor.setMode( 'source', function() { + editor.setMode( 'wysiwyg', function() { + resume( function() { + var spy = sinon.spy( ac, 'onKeyDown' ); + + this.editorBots.standard.setHtmlWithSelection( '' ); + + editor.editable().fire( 'keydown', new CKEDITOR.dom.event( {} ) ); + + spy.restore(); + + assert.isTrue( spy.called ); + + ac.destroy(); + } ); + } ); + } ); + + wait(); + }, + 'test arrow down selects next item': function() { var editor = this.editors.standard, editable = editor.editable(), diff --git a/tests/plugins/autocomplete/manual/navigation.md b/tests/plugins/autocomplete/manual/navigation.md new file mode 100644 index 00000000000..046b8680bf0 --- /dev/null +++ b/tests/plugins/autocomplete/manual/navigation.md @@ -0,0 +1,13 @@ +@bender-tags: 4.14.1, bug, 3938 +@bender-ui: collapsed +@bender-ckeditor-plugins: wysiwygarea, toolbar, basicstyles, autocomplete, textmatch, sourcearea +@bender-include: _helpers/utils.js + +1. Focus the editor. +1. Type `@`. +1. Navigate to the latest completion item using arrow keys. + + **Expected:** You can navigate completion panel using a keyboard. + +1. Switch to source area and back to content editing mode. +1. Repeat 1-3. From 307123d85148dca0cbf1145b97fd0b424f2f08de Mon Sep 17 00:00:00 2001 From: Jacek Bogdanski Date: Mon, 30 Mar 2020 14:26:19 +0200 Subject: [PATCH 3/4] Fixed IE9 bug with permission denied error. --- tests/plugins/autocomplete/autocomplete.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/plugins/autocomplete/autocomplete.js b/tests/plugins/autocomplete/autocomplete.js index ecc7ea12b7f..25adf94a59d 100644 --- a/tests/plugins/autocomplete/autocomplete.js +++ b/tests/plugins/autocomplete/autocomplete.js @@ -179,8 +179,6 @@ spy.restore(); assert.isTrue( spy.called ); - - ac.destroy(); } ); } ); } ); From 204711228b4fa67ad31063ed226e053ce1053676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Krzto=C5=84?= Date: Wed, 1 Apr 2020 10:15:34 +0200 Subject: [PATCH 4/4] Changelog entry. [skip ci] --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 157da9f026e..0814a36936f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Fixed Issues: * [#2607](https://github.com/ckeditor/ckeditor4/issues/2607): Fixed: [Emoji](https://ckeditor.com/cke4/addon/emoji) SVG icons file is not loaded in CORS context. * [#3866](https://github.com/ckeditor/ckeditor4/issues/3866): Fixed: [`config.readOnly`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-readOnly) config variable not considered for startup read-only mode of inline editor. * [#3931](https://github.com/ckeditor/ckeditor4/issues/3931): [IE] Fixed: Error is thrown when pasting using paste button after accepting browser Clipboard Access Prompt dialog. +* [#3938](https://github.com/ckeditor/ckeditor4/issues/3938): Fixed: Cannot navigate autocomplete panel via keyboard after switching to source mode. ## CKEditor 4.14