-
Notifications
You must be signed in to change notification settings - Fork 169
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
Changes from 1 commit
4578669
685ff40
2b011f2
27c11ff
f969062
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -55,6 +55,7 @@ const MouseRightButton = 2; | |||
const DRAG_ID = '_dragging'; | ||||
const IMAGE_EDIT_CLASS = 'imageEdit'; | ||||
const IMAGE_EDIT_CLASS_CARET = 'imageEditCaretColor'; | ||||
const IMAGE_EDIT_DATASET = 'data-is-editing="true"'; | ||||
|
||||
/** | ||||
* ImageEdit plugin handles the following image editing features: | ||||
|
@@ -177,6 +178,9 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin { | |||
case 'extractContentWithDom': | ||||
this.removeImageEditing(event.clonedRoot); | ||||
break; | ||||
case 'beforeSetContent': | ||||
this.beforeSetContentHandler(this.editor, event.newContent); | ||||
break; | ||||
} | ||||
} | ||||
|
||||
|
@@ -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); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the style set from core API setDOMSelection? roosterjs/packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setDOMSelection.ts Line 61 in 11c9e3e
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We add the style here |
||||
} | ||||
|
||||
/** | ||||
* EXPOSED FOR TESTING PURPOSE ONLY | ||||
*/ | ||||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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