Opened 4 years ago

Closed 4 years ago

#12855 closed Bug (duplicate)

Secondary value set doesn't work as expected in standard mode

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

Description

I just need to set a value 1, then a value 2, without a delay. However CKEditor state and behaviour is invalid.

http://ckeditor.com/demo See "Standard editor" demo.

Open JS-console then type right in your browser (I use the latest Chrome 39.0.2171.99 (64-bit) / OS X):

CKEDITOR.instances.editor1.setData('1234'); CKEDITOR.instances.editor1.setData('4567'); console.log(CKEDITOR.instances.editor1.getData())

Now, press "Source" button in the toolbar, then repeat the logging-test:

console.log(CKEDITOR.instances.editor1.getData())

Change History (6)

comment:1 Changed 4 years ago by Alexey

Inline mode works as expected. The problem only when CKEditor created in standard mode.

comment:2 Changed 4 years ago by Alexey

I know about async nature of setData… However, my code has separated parts, like

  1. create CKEditor instance
  1. clear value to the default state (that calls setData)
  1. set required value via setData … (optional)

I can't skip step 2, because I dunno anything about next step 3.

Actually I have model that simple loading and deserialising data. But before it clears all controlled widgets to their default states.

Last edited 4 years ago by Alexey (previous) (diff)

comment:3 Changed 4 years ago by Alexey

If there is no way to use setData many times without conflicts, that it looks like someone sits inside WC, you know it, and you need to access the same WC, but can't… The solution is new WC, so you're going there. By other words, in case of CKEditor – I need to create a new instance… for every setData call, just to protect from previous async-call.

My solution in cases like that is TSN. I already used it. The code is:

setVal: (val, tsn) ->
		return if tsn? && @data.tsn != tsn
		@data.cachedVal = '' + (@preSetVal(val) || '<p></p>')
		@data.tsn++
		editor = @currentEditor()
		if editor && editor.status == 'ready'
			editor.setData(@data.cachedVal)
		else
			tsn = @data.tsn
			@initDOM () => @setVal val, tsn

But it won't work for CKEditor without modifying it.

Last edited 4 years ago by Jakub Ś (previous) (diff)

comment:4 Changed 4 years ago by Jakub Ś

Status: newpending
Version: 4.4.6

If there is no way to use setData many times without conflicts

What about below code (there is a callback in setData, executed after it has finished)

var editor = CKEDITOR.replace( 'editor1', {});
editor.setData( '', function() {
    editor.setData( 'bar' );
} );				
});

IMHO it does just what you need. Please see ​http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setData.

comment:5 Changed 4 years ago by Alexey

Yep, I understand callback solution. But the problem is – I don't know anytime is next setData call dirty or not. I currently solved the problem via the flag that means any setData() in progress or not. I set the flag before calling setData, and clear it inside the callback. For setData I have the wrapper that does waiting and delayed call if previous setData is still in the progress state, it also uses TSN to prevent race condition.

comment:6 Changed 4 years ago by Jakub Ś

Resolution: duplicate
Status: pendingclosed

@UncleMiF Thank you for the input, this issue however is a duplicate of more genral one #11502

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy