Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit ce75aa8

Browse files
committed
imp
1 parent 418095d commit ce75aa8

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

packages/core/src/JWEditor.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AtomicNode } from './VNodes/AtomicNode';
1111
import { SeparatorNode } from './VNodes/SeparatorNode';
1212
import { Memory } from './Memory/Memory';
1313
import { makeVersionable, markNotVersionable } from './Memory/Versionable';
14+
import { VersionableArray } from './Memory/VersionableArray';
1415

1516
export enum Mode {
1617
CONFIGURATION = 'configuration',
@@ -61,7 +62,7 @@ export class JWEditor {
6162
};
6263
memory: Memory;
6364
memoryID = 0;
64-
private memoryInfo: { commandNames: string[] };
65+
memoryInfo: { commandNames: string[] };
6566
selection = new VSelection();
6667
loaders: Record<string, Loader> = {};
6768
private mutex = Promise.resolve();
@@ -323,9 +324,7 @@ export class JWEditor {
323324
if (isFrozen) {
324325
// Switch to the next memory slice (unfreeze the memory).
325326
this.memory.switchTo(this.memoryID.toString());
326-
const commandNames = [];
327-
markNotVersionable(commandNames);
328-
this.memoryInfo.commandNames = commandNames;
327+
this.memoryInfo.commandNames = new VersionableArray();
329328
}
330329
await callback();
331330
if (isFrozen) {

packages/plugin-dom-layout/src/ActionableDomObjectRenderer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ export class ActionableDomObjectRenderer extends AbstractRenderer<DomObject> {
7171
* @param element
7272
*/
7373
protected _updateActionables(): void {
74-
const pathChanges = this.engine.editor.memory.getChangedVersionables();
75-
for (const [n, p] of pathChanges) {
76-
console.log(n.name, p);
74+
const commandNames = this.engine.editor.memoryInfo.commandNames;
75+
if (commandNames.length === 1 && commandNames.includes('insertText')) {
76+
// By default the actionable buttons are not update for a text insertion.
77+
return;
7778
}
78-
7979
for (const [aactionable, element] of this.actionableNodes) {
8080
const editor = this.engine.editor;
8181
const select = !!aactionable.selected(editor);

packages/plugin-dom-layout/src/ActionableGroupSelectItemDomObjectRenderer.ts

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ export class ActionableGroupSelectItemDomObjectRenderer extends AbstractRenderer
122122
* @param element
123123
*/
124124
protected _updateActionables(): void {
125+
const commandNames = this.engine.editor.memoryInfo.commandNames;
126+
if (commandNames.length === 1 && commandNames.includes('insertText')) {
127+
// By default the actionable buttons are not update for a text insertion.
128+
return;
129+
}
125130
for (const [aactionable, element] of this.actionableNodes) {
126131
const editor = this.engine.editor;
127132
const select = aactionable.selected(editor);

packages/plugin-dom-layout/src/DomLayout.ts

+34-14
Original file line numberDiff line numberDiff line change
@@ -153,31 +153,51 @@ export class DomLayout<T extends DomLayoutConfig = DomLayoutConfig> extends JWPl
153153
private async _redraw(): Promise<void> {
154154
const layout = this.dependencies.get(Layout);
155155
const domLayoutEngine = layout.engines.dom as DomLayoutEngine;
156-
const pathChanges = this.editor.memory.getChangedVersionables();
156+
const pathChanges = new Map(this.editor.memory.getChangedVersionables());
157157
if (pathChanges.size) {
158158
const nodes = [];
159-
for (const [root, paths] of pathChanges) {
159+
// for (const [root] of pathChanges) {
160+
// if (
161+
// !(root instanceof AbstractNode) ||
162+
// root === this.editor.selection.anchor ||
163+
// root === this.editor.selection.focus
164+
// ) {
165+
// // Filter not VNode changes and selection change.
166+
// pathChanges.delete(root);
167+
// }
168+
// }
169+
let removedNode = false;
170+
for (const [root] of pathChanges) {
160171
if (root instanceof AbstractNode) {
161-
if (!nodes.includes(root)) {
162-
nodes.push(root);
172+
nodes.push(root);
173+
if (!root.parent) {
174+
removedNode = true;
163175
}
164-
if (paths.find(path => path[0] === 'childVNodes')) {
165-
// Need to force redrawing of children if remove a child.
166-
for (const node of [...nodes]) {
167-
if (node instanceof ContainerNode) {
168-
for (const child of node.childVNodes) {
169-
const index = nodes.indexOf(child);
170-
if (index !== -1) {
171-
nodes.splice(index, 1);
176+
}
177+
}
178+
if (removedNode) {
179+
// Need to force redrawing of children if remove a child.
180+
for (const [root, paths] of pathChanges) {
181+
if (root instanceof AbstractNode) {
182+
if (paths.find(path => path[0] === 'childVNodes')) {
183+
for (const node of [...nodes]) {
184+
if (node instanceof ContainerNode) {
185+
for (const child of node.childVNodes) {
186+
const index = nodes.indexOf(child);
187+
if (index !== -1) {
188+
nodes.splice(index, 1);
189+
}
190+
nodes.push(child);
172191
}
173-
nodes.push(child);
174192
}
175193
}
176194
}
177195
}
178196
}
179197
}
180-
console.log(nodes.map(n => n.name).filter(g => g.length > 1));
198+
199+
console.log(pathChanges);
200+
console.log(nodes.map(n => n.name));
181201
await domLayoutEngine.redraw(nodes);
182202
}
183203
}

0 commit comments

Comments
 (0)