Skip to content

Commit

Permalink
Content Model: Fix a regression of shadow edit (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Sep 8, 2023
1 parent bf80705 commit b77c854
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export const switchShadowEdit: SwitchShadowEdit = (editorCore, isOn): void => {

if (isOn != !!core.lifecycle.shadowEditFragment) {
if (isOn) {
if (!core.cachedModel) {
core.cachedModel = core.api.createContentModel(core);
}

const model = !core.cachedModel ? core.api.createContentModel(core) : null;
const range = core.api.getSelectionRange(core, true /*tryGetFromCache*/);

// Fake object, not used in Content Model Editor, just to satisfy original editor code
Expand All @@ -35,6 +32,12 @@ export const switchShadowEdit: SwitchShadowEdit = (editorCore, isOn): void => {
false /*broadcast*/
);

// This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event
// if current selection is table selection or image selection
if (!core.cachedModel && model) {
core.cachedModel = model;
}

core.lifecycle.shadowEditSelectionPath = selectionPath;
core.lifecycle.shadowEditFragment = fragment;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('switchShadowEdit', () => {

describe('was off', () => {
it('no cache, isOn', () => {
core.cachedModel = undefined;
switchShadowEdit(core, true);

expect(createContentModel).toHaveBeenCalledWith(core);
Expand Down

0 comments on commit b77c854

Please sign in to comment.