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

Content Model: Fix a regression of shadow edit #2058

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading