Skip to content

Commit

Permalink
Merge pull request #4122 from ckeditor/t/4107
Browse files Browse the repository at this point in the history
Fix autocomplete navigation with multiple instances.
  • Loading branch information
Dumluregn committed Jun 24, 2020
2 parents f8efaff + 4d8ad4a commit 21b24d9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CKEditor 4 Changelog
Fixed Issues:

* [#3795](https://github.com/ckeditor/ckeditor4/issues/3795): Fixed: Setting [`dataIndentationChars`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-dataIndentationChars) config option to an empty string is ignored and replaced by a tab (`\t`) character. Thanks to [Thomas Grinderslev](https://github.com/Znegl)!
* [#4107](https://github.com/ckeditor/ckeditor4/issues/4107): Fixed: Multiple [Autocomplete](https://ckeditor.com/cke4/addon/autocomplete) instances cause keyboard navigation issues.

## CKEditor 4.14.1

Expand Down
7 changes: 6 additions & 1 deletion plugins/autocomplete/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@
this.registerPanelNavigation();
}

editor.on( 'contentDom', this.registerPanelNavigation, this );
// Note: CKEditor's event system has a limitation that one function
// cannot be used as listener for the same event more than once. Hence, wrapper function.
// (#4107)
editor.on( 'contentDom', function() {
this.registerPanelNavigation();
}, this );
},

registerPanelNavigation: function() {
Expand Down
27 changes: 17 additions & 10 deletions tests/plugins/autocomplete/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,33 @@
wait();
},

// (#3938)
// (#3938, #4107)
'test navigation keybindings are registered after changing mode': function() {
var editor = this.editors.source,
ac = new CKEDITOR.plugins.autocomplete( editor, configDefinition );
bot = this.editorBots.standard,
ac1 = new CKEDITOR.plugins.autocomplete( editor, configDefinition ),
ac2 = new CKEDITOR.plugins.autocomplete( editor, configDefinition );

editor.setMode( 'source', function() {
editor.setMode( 'wysiwyg', function() {
resume( function() {
var spy = sinon.spy( ac, 'onKeyDown' );
testPanelEvents( ac1, 'The first autocomplete navigation bindings should work' );
testPanelEvents( ac2, 'The second autocomplete navigation bindings should work' );
} );
} );
} );

this.editorBots.standard.setHtmlWithSelection( '' );
function testPanelEvents( autocomplete, msg ) {
var spy = sinon.spy( autocomplete, 'onKeyDown' );

editor.editable().fire( 'keydown', new CKEDITOR.dom.event( {} ) );
bot.setHtmlWithSelection( '' );

spy.restore();
editor.editable().fire( 'keydown', new CKEDITOR.dom.event( {} ) );

assert.isTrue( spy.called );
} );
} );
} );
spy.restore();

assert.isTrue( spy.called, msg );
}

wait();
},
Expand Down
29 changes: 29 additions & 0 deletions tests/plugins/autocomplete/manual/sourcemode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<textarea id="editor"></textarea>

<script>
var feed = [
'john',
'thomas',
'anna',
'annabelle',
'cris',
'julia'
];

var editor = CKEDITOR.replace( 'editor', {
width: 600,
mentions: [
{
feed: feed,
minChars: 0
},
{
feed: feed,
minChars: 0,
marker: '#'
}
]
} );

bender.tools.ignoreUnsupportedEnvironment( 'mentions', editor );
</script>
19 changes: 19 additions & 0 deletions tests/plugins/autocomplete/manual/sourcemode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@bender-tags: 4.14.2, bug, 4107
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, basicstyles, mentions, sourcearea

1. Toggle source mode.
1. Focus the editor.
1. Type `@` to open completion panel.
1. Navigate through items using arrow keys.
1. Close completion panel using `esc` key.
1. Type `#` to open completion panel.
1. Navigate through items using arrow keys.

## Expected

For both completion panels under `@` and `#` characters, you should be able to navigate through items using arrow keys.

## Unexpected

Navigation keys doesn't work for both or one of completion panels after toggling source mode.

0 comments on commit 21b24d9

Please sign in to comment.