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 #133 from ckeditor/t/ckeditor5/753
Browse files Browse the repository at this point in the history
Fix: `DeleteObserver` will stop the `keydown` event when the `delete` event is stopped. Closes: ckeditor/ckeditor5#753.
  • Loading branch information
Reinmar authored Jan 16, 2018
2 parents e3c2d2e + 4874278 commit 479d043
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/deleteobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ export default class DeleteObserver extends Observer {
deleteData.unit = data.altKey ? 'word' : deleteData.unit;
deleteData.sequence = ++sequence;

// Save the event object to check later if it was stopped or not.
let event;
document.once( 'delete', evt => ( event = evt ), { priority: 'highest' } );

document.fire( 'delete', new DomEventData( document, data.domEvent, deleteData ) );

// Stop `keydown` event if `delete` event was stopped.
// https://github.com/ckeditor/ckeditor5/issues/753
if ( event && event.stop.called ) {
evt.stop();
}
} );
}

Expand Down
24 changes: 24 additions & 0 deletions tests/deleteobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@ describe( 'DeleteObserver', () => {
expect( spy.args[ 0 ][ 1 ] ).to.have.property( 'sequence', 1 );
expect( spy.args[ 1 ][ 1 ] ).to.have.property( 'sequence', 2 );
} );

it( 'should stop keydown event when delete event is stopped', () => {
const keydownSpy = sinon.spy();
viewDocument.on( 'keydown', keydownSpy );
viewDocument.on( 'delete', evt => evt.stop() );

viewDocument.fire( 'keydown', new DomEventData( viewDocument, getDomEvent(), {
keyCode: getCode( 'delete' )
} ) );

sinon.assert.notCalled( keydownSpy );
} );

it( 'should not stop keydown event when delete event is not stopped', () => {
const keydownSpy = sinon.spy();
viewDocument.on( 'keydown', keydownSpy );
viewDocument.on( 'delete', evt => evt.stop() );

viewDocument.fire( 'keydown', new DomEventData( viewDocument, getDomEvent(), {
keyCode: getCode( 'x' )
} ) );

sinon.assert.calledOnce( keydownSpy );
} );
} );

function getDomEvent() {
Expand Down

0 comments on commit 479d043

Please sign in to comment.