diff --git a/CHANGES.md b/CHANGES.md
index f5d2564dc63..28e017b1a8d 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -13,6 +13,7 @@ New Features:
Fixed Issues:
+* [#11753](http://dev.ckeditor.com/ticket/11753): Fixed: Issue with wrong checkDirty value.
* [#11830](http://dev.ckeditor.com/ticket/11830): Fixed: Issue with passing arguments into CKBuilder.
* [#11757](http://dev.ckeditor.com/ticket/11757): Fixed: Imperfections in the [Moono](http://ckeditor.com/addon/moono) skin. Thanks to [danyaPostfactum](https://github.com/danyaPostfactum)!
* [#10091](http://dev.ckeditor.com/ticket/10091): Blockquote should be treated like an object by the styles system. Thanks to [dan-james-deeson](https://github.com/dan-james-deeson)!
diff --git a/core/selection.js b/core/selection.js
index a63cf4f0d76..dc03515d7c9 100644
--- a/core/selection.js
+++ b/core/selection.js
@@ -278,9 +278,13 @@
var hiddenEl = editor._.hiddenSelectionContainer;
if ( hiddenEl ) {
+ var isDirty = editor.checkDirty();
+
editor.fire( 'lockSnapshot' );
hiddenEl.remove();
editor.fire( 'unlockSnapshot' );
+
+ !isDirty && editor.resetDirty();
}
delete editor._.hiddenSelectionContainer;
diff --git a/plugins/widget/plugin.js b/plugins/widget/plugin.js
index 76a8430fab2..6968249524c 100644
--- a/plugins/widget/plugin.js
+++ b/plugins/widget/plugin.js
@@ -1196,9 +1196,14 @@
// Fake the selection before focusing editor, to avoid unpreventable viewports scrolling
// on Webkit/Blink/IE which is done because there's no selection or selection was somewhere else than widget.
- if ( sel )
+ if ( sel ) {
+ var isDirty = this.editor.checkDirty();
+
sel.fake( this.wrapper );
+ !isDirty && this.editor.resetDirty();
+ }
+
// Always focus editor (not only when focusManger.hasFocus is false) (because of #10483).
this.editor.focus();
},
@@ -1701,9 +1706,13 @@
widgetsRepo.focused = null;
if ( widget.isInited() ) {
+ var isDirty = widget.editor.checkDirty();
+
// Widget could be destroyed in the meantime - e.g. data could be set.
widgetsRepo.fire( 'widgetBlurred', { widget: widget } );
widget.setFocused( false );
+
+ !isDirty && widget.editor.resetDirty();
}
}
@@ -2631,7 +2640,7 @@
commit: function() {
var focusedChanged = widgetsRepo.focused !== focused,
- widget;
+ widget, isDirty;
widgetsRepo.editor.fire( 'lockSnapshot' );
@@ -2641,14 +2650,23 @@
while ( ( widget = toBeDeselected.pop() ) ) {
currentlySelected.splice( CKEDITOR.tools.indexOf( currentlySelected, widget ), 1 );
// Widget could be destroyed in the meantime - e.g. data could be set.
- if ( widget.isInited() )
+ if ( widget.isInited() ) {
+ isDirty = widget.editor.checkDirty();
+
widget.setSelected( false );
+
+ !isDirty && widget.editor.resetDirty();
+ }
}
if ( focusedChanged && focused ) {
+ isDirty = widgetsRepo.editor.checkDirty();
+
widgetsRepo.focused = focused;
widgetsRepo.fire( 'widgetFocused', { widget: focused } );
focused.setFocused( true );
+
+ !isDirty && widgetsRepo.editor.resetDirty();
}
while ( ( widget = toBeSelected.pop() ) ) {
diff --git a/tests/plugins/widget/checkdirty.js b/tests/plugins/widget/checkdirty.js
new file mode 100644
index 00000000000..7249b870a67
--- /dev/null
+++ b/tests/plugins/widget/checkdirty.js
@@ -0,0 +1,62 @@
+/* bender-ckeditor-plugins: widget */
+
+(function() {
+ 'use strict';
+
+ bender.test( {
+ 'async:init': function() {
+ var tc = this;
+
+ bender.tools.setUpEditors( {
+ editor: {
+ name: 'editor1',
+ startupData: 'foofoo',
+ config: {
+ allowedContent: true,
+ on: {
+ pluginsLoaded: function( evt ) {
+ var ed = evt.editor;
+
+ ed.widgets.add( 'testwidget', {} );
+ }
+ }
+ }
+ }
+ }, function( editors, bots ) {
+ tc.editor = bots.editor.editor;
+
+ tc.callback();
+ } );
+ },
+
+ 'test check dirty is false after widget focus': function() {
+ var widget = this.editor.widgets.instances[ 1 ];
+
+ assert.isFalse( this.editor.checkDirty() );
+ widget.focus();
+ assert.isFalse( this.editor.checkDirty() );
+ },
+
+ 'test check dirty is true after modifications': function() {
+ var widget = this.editor.widgets.instances[ 1 ];
+
+ assert.isFalse( this.editor.checkDirty() );
+
+ // Clear selection
+ var range = this.editor.createRange();
+ var lastElement = this.editor.document.getById( 'two' );
+ range.moveToPosition( lastElement, CKEDITOR.POSITION_BEFORE_END );
+ this.editor.getSelection().selectRanges( [ range ] );
+
+ assert.isFalse( this.editor.checkDirty() );
+
+ // Make some changes in editor
+ widget.addClass( 'test' );
+
+ assert.isTrue( this.editor.checkDirty() );
+ widget.focus();
+ assert.isTrue( this.editor.checkDirty() );
+ }
+ } );
+
+})();
\ No newline at end of file