Skip to content

Commit

Permalink
Merge pull request #1589 from ckeditor/t/1570
Browse files Browse the repository at this point in the history
Disabled cutting widget in a readonly mode using cmd/ctrl + x keys
  • Loading branch information
Comandeer authored Feb 7, 2018
2 parents 1e4ca70 + 2226211 commit 5db0c71
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Fixed Issues:
* [#1470](https://github.com/ckeditor/ckeditor-dev/issues/1470): Fixed: [Balloon Toolbar](https://ckeditor.com/cke4/addon/balloontoolbar) is not visible after drag and drop of a widget it is attached to.
* [#1535](https://github.com/ckeditor/ckeditor-dev/issues/1535): Fixed: Improve [Widget](https://ckeditor.com/cke4/addon/widget) mouse over border contrast.
* [#1516](https://github.com/ckeditor/ckeditor-dev/issues/1516): Fixed: Fake selection allows removing in a readonly mode using `Backspace`/`Delete` keys.
* [#1570](https://github.com/ckeditor/ckeditor-dev/issues/1570): Fixed: Fake selection allows cutting in a readonly mode using `Ctrl`/`Cmd` + `X` keys.

API Changes:

Expand Down
3 changes: 2 additions & 1 deletion plugins/widget/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3191,7 +3191,8 @@

editor.fire( 'unlockSnapshot' );

if ( isCut ) {
// Prevent cutting in read-only editor (#1570).
if ( isCut && !editor.readOnly ) {
widget.repository.del( widget );
editor.fire( 'saveSnapshot' );
}
Expand Down
10 changes: 10 additions & 0 deletions tests/plugins/widget/manual/readonly.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<textarea id="editor1" cols="10" rows="10"><p>[[placeholder]] foo bar</p></textarea>

<script>
CKEDITOR.replace( 'editor1', { readOnly: true } );

// Test has been ignored for IE due to #1575 issue. Remove this ignore statement after the issue fix.
if ( CKEDITOR.env.ie && !CKEDITOR.env.edge ) {
bender.ignore();
}
</script>
16 changes: 16 additions & 0 deletions tests/plugins/widget/manual/readonly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@bender-tags: selection, fake, widget, 4.9.0, bug, 1570
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, placeholder, basicstyles, toolbar, floatingspace

1. Focus the placeholder widget.
2. Blur the placeholder widget.
3. Focus placeholder widget again.
4. Press `ctrl/cmd + x` key.

## Expected

The placeholder widget shouldn't change.

## Unexpected

The placeholder widget has been deleted.
44 changes: 43 additions & 1 deletion tests/plugins/widget/widgetsintegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
}

bender.test( {
tearDown: function() {
this.editor.setReadOnly( false );
},

'test initializing widgets': function() {
var editor = this.editor;

Expand Down Expand Up @@ -635,6 +639,44 @@
} );
},

// #1570
'test cutting single focused widget with readonly mode': function() {
// Test has been ignored for IE due to #1575 issue. Remove this ignore statement after the issue fix.
if ( CKEDITOR.env.ie && !CKEDITOR.env.edge ) {
assert.ignore();
}

var editor = this.editor;

this.editorBot.setData( '<p>X</p><p id="w1" data-widget="test2">A</p><p>X</p>', function() {
var widget = getWidgetById( editor, 'w1' ),
selectionChanged = 0;

widget.focus();

editor.on( 'selectionChange', function() {
selectionChanged += 1;
} );

editor.setReadOnly( true );

editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.CTRL + 88 } ) );

var copybin = editor.document.getById( 'cke_copybin' ),
selContainer = editor.getSelection().getCommonAncestor();

assert.isTrue( !!copybin, 'copybin was created' );
assert.isTrue( copybin.contains( selContainer ) || copybin.equals( selContainer ), 'selection was moved to the copybin' );

wait( function() {
assert.isTrue( selectionChanged == 0, 'selection has not been changed' );
assert.isTrue( !!getWidgetById( editor, 'w1' ), 'widget has not been deleted' );
assert.isFalse( !!editor.getSelection().isFake, 'selection is not faked' );
assert.isFalse( !!editor.document.getById( 'cke_copybin' ), 'copybin was removed' );
}, 150 );
} );
},

'test pasting single focused widget': function() {
var editor = this.editor;

Expand Down Expand Up @@ -999,4 +1041,4 @@
} );
}
} );
} )();
} )();

0 comments on commit 5db0c71

Please sign in to comment.