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

Stop editing when content changed #2931

Merged
merged 5 commits into from
Jan 28, 2025
Merged

Conversation

juliaroldi
Copy link
Contributor

@juliaroldi juliaroldi commented Jan 28, 2025

Before setting new content into the editor, check if it has the 'data-is-editing="true"' dataset and remove it. Also stop editing the image when the content changed.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@juliaroldi juliaroldi marked this pull request as draft January 28, 2025 19:14
@@ -279,6 +283,11 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
}
}

private beforeSetContentHandler(editor: IEditor, newContent: string) {
newContent.replace(IMAGE_EDIT_DATASET, '');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this can work since you didn't use the return value?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing the source HTML, I prefer to do it in DOM tree, when handling ContentChangedEvent and check change source is setContent

@@ -279,6 +283,11 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
}
}

private beforeSetContentHandler(editor: IEditor, newContent: string) {
newContent.replace(IMAGE_EDIT_DATASET, '');
editor?.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"beforeSetContent" is a legacy event from v8. Since there is no API "setContent" in v9, I prefer not use this event. Can we do this in ContentChangedEvent? We just need to make sure do not reset cursor style if images is still selected.

Actually we should do that in SelectionPlugin since this problem can still exist if ImageEditPlugin is not added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just testing in OWA right now and remove the dataset in new content worked, but the remove caret styled persisted, I'm testing using ContentChangedEvent right now. I think we should remove the caret style in ImageEdit, since we add this style when we add the image edit wrapper.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the style set from core API setDOMSelection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juliaroldi juliaroldi changed the title Remove image "isEditing" dataset Stop editing when content changed Jan 28, 2025
juliaroldi and others added 3 commits January 28, 2025 18:32
@juliaroldi juliaroldi marked this pull request as ready for review January 28, 2025 21:36
@juliaroldi juliaroldi merged commit 555c239 into master Jan 28, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants