Skip to content

Commit a2facd8

Browse files
committed
Merge branch 't/11753'
2 parents a8fe468 + e14c014 commit a2facd8

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ New Features:
1313

1414
Fixed Issues:
1515

16+
* [#11753](http://dev.ckeditor.com/ticket/11753): Fixed: Issue with wrong checkDirty value.
1617
* [#11830](http://dev.ckeditor.com/ticket/11830): Fixed: Issue with passing arguments into CKBuilder.
1718
* [#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)!
1819
* [#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)!

core/selection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,13 @@
278278
var hiddenEl = editor._.hiddenSelectionContainer;
279279

280280
if ( hiddenEl ) {
281+
var isDirty = editor.checkDirty();
282+
281283
editor.fire( 'lockSnapshot' );
282284
hiddenEl.remove();
283285
editor.fire( 'unlockSnapshot' );
286+
287+
!isDirty && editor.resetDirty();
284288
}
285289

286290
delete editor._.hiddenSelectionContainer;

plugins/widget/plugin.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,14 @@
11961196

11971197
// Fake the selection before focusing editor, to avoid unpreventable viewports scrolling
11981198
// on Webkit/Blink/IE which is done because there's no selection or selection was somewhere else than widget.
1199-
if ( sel )
1199+
if ( sel ) {
1200+
var isDirty = this.editor.checkDirty();
1201+
12001202
sel.fake( this.wrapper );
12011203

1204+
!isDirty && this.editor.resetDirty();
1205+
}
1206+
12021207
// Always focus editor (not only when focusManger.hasFocus is false) (because of #10483).
12031208
this.editor.focus();
12041209
},
@@ -1701,9 +1706,13 @@
17011706
widgetsRepo.focused = null;
17021707

17031708
if ( widget.isInited() ) {
1709+
var isDirty = widget.editor.checkDirty();
1710+
17041711
// Widget could be destroyed in the meantime - e.g. data could be set.
17051712
widgetsRepo.fire( 'widgetBlurred', { widget: widget } );
17061713
widget.setFocused( false );
1714+
1715+
!isDirty && widget.editor.resetDirty();
17071716
}
17081717
}
17091718

@@ -2631,7 +2640,7 @@
26312640

26322641
commit: function() {
26332642
var focusedChanged = widgetsRepo.focused !== focused,
2634-
widget;
2643+
widget, isDirty;
26352644

26362645
widgetsRepo.editor.fire( 'lockSnapshot' );
26372646

@@ -2641,14 +2650,23 @@
26412650
while ( ( widget = toBeDeselected.pop() ) ) {
26422651
currentlySelected.splice( CKEDITOR.tools.indexOf( currentlySelected, widget ), 1 );
26432652
// Widget could be destroyed in the meantime - e.g. data could be set.
2644-
if ( widget.isInited() )
2653+
if ( widget.isInited() ) {
2654+
isDirty = widget.editor.checkDirty();
2655+
26452656
widget.setSelected( false );
2657+
2658+
!isDirty && widget.editor.resetDirty();
2659+
}
26462660
}
26472661

26482662
if ( focusedChanged && focused ) {
2663+
isDirty = widgetsRepo.editor.checkDirty();
2664+
26492665
widgetsRepo.focused = focused;
26502666
widgetsRepo.fire( 'widgetFocused', { widget: focused } );
26512667
focused.setFocused( true );
2668+
2669+
!isDirty && widgetsRepo.editor.resetDirty();
26522670
}
26532671

26542672
while ( ( widget = toBeSelected.pop() ) ) {

tests/plugins/widget/checkdirty.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* bender-ckeditor-plugins: widget */
2+
3+
(function() {
4+
'use strict';
5+
6+
bender.test( {
7+
'async:init': function() {
8+
var tc = this;
9+
10+
bender.tools.setUpEditors( {
11+
editor: {
12+
name: 'editor1',
13+
startupData: '<b id="one" data-widget="testwidget">foo</b><b id="two" data-widget="testwidget">foo</b>',
14+
config: {
15+
allowedContent: true,
16+
on: {
17+
pluginsLoaded: function( evt ) {
18+
var ed = evt.editor;
19+
20+
ed.widgets.add( 'testwidget', {} );
21+
}
22+
}
23+
}
24+
}
25+
}, function( editors, bots ) {
26+
tc.editor = bots.editor.editor;
27+
28+
tc.callback();
29+
} );
30+
},
31+
32+
'test check dirty is false after widget focus': function() {
33+
var widget = this.editor.widgets.instances[ 1 ];
34+
35+
assert.isFalse( this.editor.checkDirty() );
36+
widget.focus();
37+
assert.isFalse( this.editor.checkDirty() );
38+
},
39+
40+
'test check dirty is true after modifications': function() {
41+
var widget = this.editor.widgets.instances[ 1 ];
42+
43+
assert.isFalse( this.editor.checkDirty() );
44+
45+
// Clear selection
46+
var range = this.editor.createRange();
47+
var lastElement = this.editor.document.getById( 'two' );
48+
range.moveToPosition( lastElement, CKEDITOR.POSITION_BEFORE_END );
49+
this.editor.getSelection().selectRanges( [ range ] );
50+
51+
assert.isFalse( this.editor.checkDirty() );
52+
53+
// Make some changes in editor
54+
widget.addClass( 'test' );
55+
56+
assert.isTrue( this.editor.checkDirty() );
57+
widget.focus();
58+
assert.isTrue( this.editor.checkDirty() );
59+
}
60+
} );
61+
62+
})();

0 commit comments

Comments
 (0)