Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12031 closed Bug (invalid)

"change"-event not fired on changes in source-code-mode

Reported by: Urs Wolfer Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: Cc:

Description

In WYSIWYG-mode, a change event is fired after every key-event. This is not the case in source-mode.

You can reproduce this with "Standard editor" example (http://ckeditor.com/demo) with the following code:

CKEDITOR.instances["editor1"].on("change", function(e) {console.log("change: " + e.editor.getData())})

I have worked around this issue by listening to the "key" event.

See also: http://stackoverflow.com/questions/17358203/how-to-detect-ckeditor-source-mode-on-change-event

Change History (7)

comment:1 Changed 10 years ago by Piotrek Koszuliński

Resolution: invalid
Status: newclosed
Version: 4.4.1

Change event was defined only for wysiwyg mode, because it's very complicated to implement in this mode and it's impossible to implement in few lines of code anywhere outside editor's undo manager. On the contrary, in the source mode it's easy using e.g. the native input event (does not work on IE8) or keyup listener and value comparison. And it can be done independently from core.

So, this is not a bug - this is an intended behaviour of the change event. If you think that it should be also fired in source mode, then please report a new feature request with a an explanation why should core of editor handle this. Note that this is a perfect situation for a 3rd plugin, so we will not like to spend the core team time on this.

comment:2 Changed 10 years ago by Piotrek Koszuliński

BTW. firing #change in source mode has one problem - it would be fired also when data is not a correct HTML. That's an additional reason why CKEditor does not do this by default.

comment:3 Changed 10 years ago by Urs Wolfer

Reinmar, thanks for the clarification.

IMHO, two things should be changed

  • Add note for that behavior in api docs. I'll do that an create a pull request (PR 103).
  • You should get a "change"-event at least when you switches back to wysiwg-mode. Use-case: A save button is disabled by default, it gets activated once there are changes in the editor. The user edits all code in source-mode and switches back to the wysiwyg-mode. The save button is not activated because the change-event is fired only after he does a change in wysiwyg-mode.
Last edited 10 years ago by Urs Wolfer (previous) (diff)

comment:4 Changed 10 years ago by Piotrek Koszuliński

Hey, thanks for PR. I'll merge it later today.

Regarding the change event fired after leaving source mode - it is fired when a change has been made in source mode. So source mode is understood as a one huge change (if any change has been made).

In your scenario, when a change has not been made while user is in source mode, on switch to wysiwyg mode you should restore the save button state from the moment before user switched to source mode.

comment:5 in reply to:  4 Changed 10 years ago by Urs Wolfer

Replying to Reinmar:

Regarding the change event fired after leaving source mode - it is fired when a change has been made in source mode. So source mode is understood as a one huge change (if any change has been made).

What event is fired when leaving source mode? I think only "mode" event is fired, but not "change", even when a change has been made in source mode. Probably I didn't understand your reply correctly.

comment:6 Changed 10 years ago by Piotrek Koszuliński

You understood my reply correctly :) There's a change event fired when you leave source mode (if a change has been made in source mode). It works at least on nightly in the replacebycode sample. Are you sure you check the latest version of CKEditor?

Check: http://nightly.ckeditor.com/14-05-30-06-06/standard/samples/replacebycode.html

 CKEDITOR.instances.editor1.on('change', function() { console.log( 'change' ) } );

WFM.

Besides change, there's also mode event, dataReady, contentDom and many more events fired when switching to source mode.

comment:7 in reply to:  6 Changed 10 years ago by Urs Wolfer

Replying to Reinmar:

You understood my reply correctly :) There's a change event fired when you leave source mode (if a change has been made in source mode). It works at least on nightly in the replacebycode sample. Are you sure you check the latest version of CKEditor?

You are right, this works fine in recent 4.4 builds :) Great.

Thanks for your support.

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy