Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #30 from ckeditor/t/29
Browse files Browse the repository at this point in the history
Other: Switched to handling deletion around widgets by using the `delete` event instead of listening directly on key events. Closes #29.
  • Loading branch information
Reinmar authored Dec 22, 2017
2 parents 5bfd6bd + 748bf29 commit ee6cc95
Show file tree
Hide file tree
Showing 3 changed files with 422 additions and 437 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@ckeditor/ckeditor5-theme-lark": "^1.0.0-alpha.2"
},
"devDependencies": {
"@ckeditor/ckeditor5-typing": "^1.0.0-alpha.2",
"eslint": "^4.8.0",
"eslint-config-ckeditor5": "^1.0.7",
"husky": "^0.14.3",
Expand Down
20 changes: 9 additions & 11 deletions src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export default class Widget extends Plugin {

// Handle custom keydown behaviour.
this.listenTo( viewDocument, 'keydown', ( ...args ) => this._onKeydown( ...args ), { priority: 'high' } );

// Handle custom delete behaviour.
this.listenTo( viewDocument, 'delete', ( evt, data ) => {
if ( this._handleDelete( data.direction == 'forward' ) ) {
data.preventDefault();
evt.stop();
}
}, { priority: 'high' } );
}

/**
Expand Down Expand Up @@ -141,9 +149,7 @@ export default class Widget extends Plugin {

// Checks if the keys were handled and then prevents the default event behaviour and stops
// the propagation.
if ( isDeleteKeyCode( keyCode ) ) {
wasHandled = this._handleDelete( isForward );
} else if ( isArrowKeyCode( keyCode ) ) {
if ( isArrowKeyCode( keyCode ) ) {
wasHandled = this._handleArrowKeys( isForward );
} else if ( isSelectAllKeyCode( domEventData ) ) {
wasHandled = this._selectAllNestedEditableContent() || this._selectAllContent();
Expand Down Expand Up @@ -356,14 +362,6 @@ function isArrowKeyCode( keyCode ) {
keyCode == keyCodes.arrowdown;
}

// Returns 'true' if provided key code represents one of the delete keys: delete or backspace.
//
// @param {Number} keyCode
// @returns {Boolean}
function isDeleteKeyCode( keyCode ) {
return keyCode == keyCodes.delete || keyCode == keyCodes.backspace;
}

// Returns 'true' if provided (DOM) key event data corresponds with the Ctrl+A keystroke.
//
// @param {module:engine/view/observer/keyobserver~KeyEventData} domEventData
Expand Down
Loading

0 comments on commit ee6cc95

Please sign in to comment.