Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source editing doesn't save unless going back to WYSIWYG #11008

Closed
fspreck-indiscale opened this issue Dec 15, 2021 · 13 comments · Fixed by #13784
Closed

Source editing doesn't save unless going back to WYSIWYG #11008

fspreck-indiscale opened this issue Dec 15, 2021 · 13 comments · Fixed by #13784
Assignees
Labels
squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@fspreck-indiscale
Copy link

Maybe this is rather a question than a bug but I couldn't find a bettter place to submit it.

We're using CKeditor to edit the (mardown) contents of a textarea. Unfortuantely, the textarea isn't part of a submittable form and its contents (among others) are sent to a server after manually saving (and thereby closing the editing area). That's why I use a simple

editor.model.document.on("change:data", (e) => {
    editor.updateSourceElement();
});

to ensure that the textarea always contains the user input of the WYSIWYG editor which works fine, except for input made from within the source editor. There, the change:data event never fires and subsequently, nothing is changed.

For CKEditor 4 I found this. Is there something similar for CKEditor 5? What am I missing?

📝 Provide detailed reproduction steps (if any)

  1. Use a manual saving setup as above
  2. Enter source mode and change something
  3. Save (or observe the change:data event) and see that nothing happens

✔️ Expected result

Changing something while in source editing should also trigger the

❌ Actual result

Only after going back to the WYSIWYG mode, the changes are applied (i.e., the change:data event is fired).

📃 Other details

  • Browser: Firefox 95.0, Chromium 96.0.4664.110
  • OS: Arch Linux
  • First affected CKEditor version: 31.0.0
  • Installed CKEditor plugins: Markdown, SourceEditing

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@Dumluregn
Copy link
Contributor

For anyone struggling with this issue - if you need to sync data on some trigger (e.g. button click), you can use _updateEditorData() method of the SourceEditing plugin - https://ckeditor.com/docs/ckeditor5/latest/api/module_source-editing_sourceediting-SourceEditing.html#function-_updateEditorData. See how it works below:

@Reinmar
Copy link
Member

Reinmar commented Mar 13, 2023

In general, every approach that retrieves data from the editor on a frequent action (like change:data) is quite non-optimal. The editor set/get data pipeline isn't designed for such frequent use. It's just synchronous and too slow to be called upon frequent user actions. It may cause the editor to become less-responsive.

Therefore, a much better solution is indeed triggering data retrieval/save on some reasonable trigger like "save" button click or a debounced autosave callback. So, @Dumluregn's response makes a lot of sense actually. 

It also makes a lot of sense that the editor data is not automatically updated by the source mode. It may simply cause a lot of issues with some partially incomplete HTML being forced into the editor's data pipeline, causing weird effects in there.

The only issue here, IMO, is that _updateEditorData() is a private method. IMO, we should make it public and that's it.

@Reinmar Reinmar added the squad:core Issue to be handled by the Core team. label Mar 13, 2023
@Witoso
Copy link
Member

Witoso commented Mar 27, 2023

@Reinmar do we treat a change in a private method as a breaking change?

Possible solution that could benefit from TS:

  1. Change the method name to one without an underscore.
  2. Do the forward from the underscore method.
  3. Add deprecated that will inform the dev about deprecation.

But we are not sure if internal API is a part of breaking changes. Minor breaking change?

@CKEditorBot CKEditorBot added the status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. label Mar 27, 2023
@mremiszewski mremiszewski self-assigned this Mar 28, 2023
@CKEditorBot CKEditorBot added status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. and removed status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Mar 28, 2023
@Witoso
Copy link
Member

Witoso commented Mar 29, 2023

Decision: we don't treat private API as a breaking change.

arkflpc added a commit that referenced this issue Apr 3, 2023
…-source-mode

Feature (source-editing): Make `SourceEditing.updateEditorData` method public to allow saving source editing data independently of the UI. Closes #11008.
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Apr 3, 2023
@CKEditorBot CKEditorBot added this to the iteration 62 milestone Apr 3, 2023
@aljaznuncic
Copy link

For anyone struggling with this issue - if you need to sync data on some trigger (e.g. button click), you can use _updateEditorData() method of the SourceEditing plugin - https://ckeditor.com/docs/ckeditor5/latest/api/module_source-editing_sourceediting-SourceEditing.html#function-_updateEditorData. See how it works below:

224675810-0b4c9553-c65c-4f24-996b-d42e834aaf43.gif

How can you do this with angular and ckeditor custom build ("@ckeditor/ckeditor5-source-editing": "^38.0.1"). I got error Uncaught ReferenceError: editor is not defined

@Witoso
Copy link
Member

Witoso commented Jun 1, 2023

@aljaznuncic
Copy link

@Witoso I still have a problem.

When I'm in SourceEditing mode, ngModel should be updated with click on button UPDATE SOURCE, but it isn't (Browser freeze)

Here is the link to the code: https://github.com/aljaznuncic/testCkeditor

@Witoso
Copy link
Member

Witoso commented Jun 20, 2023

@aljaznuncic looks like a known problem in Angular integration (ckeditor/ckeditor5-angular#360), let's move the discussion there.

@BashisthaSudeep
Copy link

I'm having the same issue using https://github.com/ckeditor/strapi-plugin-ckeditor where any changes on source editor doesn't trigger the update and the changes aren't saved.

@Apederli
Copy link

@aljaznuncic
When I opened sourceEditing in my angular project, I couldnt save the edited text. So ngModel didn't change. I found a solution for my own.
Before saving, I closed the sourceEditing; like this:
const button = this.el.nativeElement.querySelector('.ck-source-editing-button');
if (button && button.classList.contains('ck-on')) {
button.click();
}

@aimeos
Copy link

aimeos commented Mar 6, 2024

@Witoso The blur event is also not fired if the editor is in source edit mode. According to the explanation of @Reinmar, this would be a good option performance-wise but currently doesn't work. Any plans to add the blur event to the source edit mode?

@Witoso
Copy link
Member

Witoso commented Mar 7, 2024

@aimeos you posted the same comment to 3 issues. In the future, please create a new one.

Any plans to add the blur event to the source edit mode?

No plans for now as source editing is not directly editor instance. Create a ticket and we store this improvement.

@aimeos
Copy link

aimeos commented Mar 8, 2024

@Witoso A new Github issue or somewhere else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants