diff --git a/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/ContentModelEditPlugin.ts b/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/ContentModelEditPlugin.ts index cdfe998c906..c8d6e752571 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/ContentModelEditPlugin.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/ContentModelEditPlugin.ts @@ -96,6 +96,7 @@ export default class ContentModelEditPlugin implements EditorPlugin { case PluginEventType.ContentChanged: case PluginEventType.MouseUp: + case PluginEventType.SelectionChanged: this.editor.cacheContentModel(null); break; } diff --git a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelEditPluginTest.ts b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelEditPluginTest.ts index 7f863bd2f2e..329be288b9f 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelEditPluginTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelEditPluginTest.ts @@ -186,6 +186,18 @@ describe('ContentModelEditPlugin', () => { ); expect(cacheContentModel).not.toHaveBeenCalled(); }); + + it('SelectionChanged event should clear cached model', () => { + const plugin = new ContentModelEditPlugin(); + + plugin.initialize(editor); + plugin.onPluginEvent({ + eventType: PluginEventType.SelectionChanged, + selectionRangeEx: null!, + }); + + expect(cacheContentModel).toHaveBeenCalledWith(null); + }); }); describe('onPluginEvent, no need to go through Content Model', () => {