From 685cfff07509f632dbf5bc60b2e76ae7be1cd7d4 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Mon, 18 Sep 2017 15:00:45 +0200 Subject: [PATCH] Prevents from deleting widget when the read only mode is enabled. --- src/widget.js | 5 +++++ tests/widget.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/widget.js b/src/widget.js index f959b10e..bdaa05e9 100644 --- a/src/widget.js +++ b/src/widget.js @@ -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; diff --git a/tests/widget.js b/tests/widget.js index 6f7d94cc..e06adfe8 100644 --- a/tests/widget.js +++ b/tests/widget.js @@ -606,6 +606,54 @@ describe( 'Widget', () => { '' + 'foo' ); + + it( 'does nothing when editor when read only mode is enabled (delete)', () => { + setModelData( doc, + 'foo' + + '' + + '
[]
' + + 'foo' + ); + + editor.isReadOnly = true; + + viewDocument.fire( 'keydown', new DomEventData( + viewDocument, + { target: document.createElement( 'div' ), preventDefault: () => {} }, + { keyCode: keyCodes.backspace } + ) ); + + expect( getModelData( doc ) ).to.equal( + 'foo' + + '' + + '
[]
' + + 'foo' + ); + } ); + + it( 'does nothing when editor when read only mode is enabled (forward delete)', () => { + setModelData( doc, + 'foo' + + '
[]
' + + '' + + 'foo' + ); + + editor.isReadOnly = true; + + viewDocument.fire( 'keydown', new DomEventData( + viewDocument, + { target: document.createElement( 'div' ), preventDefault: () => {} }, + { keyCode: keyCodes.delete } + ) ); + + expect( getModelData( doc ) ).to.equal( + 'foo' + + '
[]
' + + '' + + 'foo' + ); + } ); } ); describe( 'arrows', () => {