Skip to content

Commit

Permalink
Merge pull request #666 from ckeditor/t/554
Browse files Browse the repository at this point in the history
First alteration of a text after pasting (ctrl+v) does not trigger 'change' event
  • Loading branch information
Comandeer authored Aug 18, 2017
2 parents e8348ce + 6ec3c00 commit 2a771cf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

## CKEditor 4.7.3

Fixed Issues:

* [#554](https://github.com/ckeditor/ckeditor-dev/issues/554): Fixed: [`change`](https://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-change) event not fired when typing the first character after pasting into the editor. Thanks to [Daniel Miller](https://github.com/millerdev)!

## CKEditor 4.7.2

New Features:
Expand Down
11 changes: 11 additions & 0 deletions plugins/undo/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,14 @@
this.ignoreInputEvent = true;
},

/**
* Stop ignoring `input` events.
* @since 4.7.3
*/
activateInputEventListener: function() {
this.ignoreInputEvent = false;
},

/**
* Attaches editable listeners required to provide the undo functionality.
*/
Expand Down Expand Up @@ -1080,6 +1088,9 @@
editable.attachListener( editable, 'paste', that.ignoreInputEventListener, that, null, 999 );
editable.attachListener( editable, 'drop', that.ignoreInputEventListener, that, null, 999 );

// After paste we need to re-enable input event listener (#554).
editor.on( 'afterPaste', that.activateInputEventListener, that, null, 999 );

// Click should create a snapshot if needed, but shouldn't cause change event.
// Don't pass onNavigationKey directly as a listener because it accepts one argument which
// will conflict with evt passed to listener.
Expand Down
23 changes: 22 additions & 1 deletion tests/plugins/undo/change.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* bender-tags: editor */
/* bender-ckeditor-plugins: undo,basicstyles,toolbar,wysiwygarea */
/* bender-ckeditor-plugins: undo,clipboard,basicstyles,toolbar,wysiwygarea */
/* global undoEventDispatchTestsTools */

( function() {
Expand Down Expand Up @@ -180,6 +180,27 @@
// After setting text - caret is moved to beginning. We don't care - it does not change nothing.
keyTools.keyEvent( keyCodesEnum.LEFT, null, true );
} );
},

// #554
'test change event fired on type after paste': function() {
this.editorBot.setHtmlWithSelection( '<p>foo^</p>' );

var that = this,
keys = this.keyTools.keyCodesEnum;

bender.tools.emulatePaste( this.editor, 'PASTE' );

this.editor.once( 'afterPaste', function() {
resume( function() {
changeCounter = 0;
that.checkChange( function() {
that.keyTools.keyEvent( keys.KEY_G );
} );
} );
} );

wait();
}
} );

Expand Down
14 changes: 14 additions & 0 deletions tests/plugins/undo/manual/changeevent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="editor1">
<p>Paste something here:</p>
</div>
<div id="changes"></div>

<script>
var i = 1;
var changes = document.getElementById( 'changes' );
CKEDITOR.replace( 'editor1' ).on("change", function () {
var elem = document.createElement( 'div' );
elem.innerText = 'changes ' + i++;
changes.appendChild( elem );
});
</script>
10 changes: 10 additions & 0 deletions tests/plugins/undo/manual/changeevent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@bender-tags: 554, 4.7.3, bug
@bender-ui: collapsed
@bender-ckeditor-plugins: undo,clipboard,basicstyles,toolbar,wysiwygarea

----

1. Paste some text into the editor.
2. Type a single character after pasting.

**Expected:** There should be exactly two change events shown below the editor.

0 comments on commit 2a771cf

Please sign in to comment.