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 #21 from ckeditor/t/6
Browse files Browse the repository at this point in the history
Fix: <kbd>Backspace</kbd> and <kbd>Delete</kbd> should not delete a widget when the editor is in the read-only mode. Closes #6.
  • Loading branch information
Reinmar authored Sep 20, 2017
2 parents 58497a8 + 685cfff commit 5f64125
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export default class Widget extends Plugin {
* @returns {Boolean|undefined} Returns `true` if keys were handled correctly.
*/
_handleDelete( isForward ) {
// Do nothing when the read only mode is enabled.
if ( this.editor.isReadOnly ) {
return;
}

const modelDocument = this.editor.document;
const modelSelection = modelDocument.selection;

Expand Down
48 changes: 48 additions & 0 deletions tests/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,54 @@ describe( 'Widget', () => {
'</blockQuote>' +
'<paragraph>foo</paragraph>'
);

it( 'does nothing when editor when read only mode is enabled (delete)', () => {
setModelData( doc,
'<paragraph>foo</paragraph>' +
'<image></image>' +
'<blockQuote><paragraph>[]</paragraph></blockQuote>' +
'<paragraph>foo</paragraph>'
);

editor.isReadOnly = true;

viewDocument.fire( 'keydown', new DomEventData(
viewDocument,
{ target: document.createElement( 'div' ), preventDefault: () => {} },
{ keyCode: keyCodes.backspace }
) );

expect( getModelData( doc ) ).to.equal(
'<paragraph>foo</paragraph>' +
'<image></image>' +
'<blockQuote><paragraph>[]</paragraph></blockQuote>' +
'<paragraph>foo</paragraph>'
);
} );

it( 'does nothing when editor when read only mode is enabled (forward delete)', () => {
setModelData( doc,
'<paragraph>foo</paragraph>' +
'<blockQuote><paragraph>[]</paragraph></blockQuote>' +
'<image></image>' +
'<paragraph>foo</paragraph>'
);

editor.isReadOnly = true;

viewDocument.fire( 'keydown', new DomEventData(
viewDocument,
{ target: document.createElement( 'div' ), preventDefault: () => {} },
{ keyCode: keyCodes.delete }
) );

expect( getModelData( doc ) ).to.equal(
'<paragraph>foo</paragraph>' +
'<blockQuote><paragraph>[]</paragraph></blockQuote>' +
'<image></image>' +
'<paragraph>foo</paragraph>'
);
} );
} );

describe( 'arrows', () => {
Expand Down

0 comments on commit 5f64125

Please sign in to comment.