Skip to content

Commit

Permalink
Merge branch 't/11753'
Browse files Browse the repository at this point in the history
  • Loading branch information
adelura committed Jun 16, 2014
2 parents a8fe468 + e14c014 commit a2facd8
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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)!
Expand Down
4 changes: 4 additions & 0 deletions core/selection.js
Expand Up @@ -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;
Expand Down
24 changes: 21 additions & 3 deletions plugins/widget/plugin.js
Expand Up @@ -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();
},
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -2631,7 +2640,7 @@

commit: function() {
var focusedChanged = widgetsRepo.focused !== focused,
widget;
widget, isDirty;

widgetsRepo.editor.fire( 'lockSnapshot' );

Expand All @@ -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() ) ) {
Expand Down
62 changes: 62 additions & 0 deletions 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: '<b id="one" data-widget="testwidget">foo</b><b id="two" data-widget="testwidget">foo</b>',
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() );
}
} );

})();

0 comments on commit a2facd8

Please sign in to comment.