Fix history - the 2nd installment (#1014)
* don't regenerate versionNonce on pushEntry * fix history handling around multi-point arrows * remove filtering from getElementMap helper
This commit is contained in:
parent
1d393a4ea0
commit
fda06e4fc3
@ -332,7 +332,7 @@ export class App extends React.Component<any, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
}, [] as any)
|
}, [] as Mutable<typeof restoredState.elements>)
|
||||||
// add local elements that weren't deleted or on remote
|
// add local elements that weren't deleted or on remote
|
||||||
.concat(...Object.values(localElementMap)),
|
.concat(...Object.values(localElementMap)),
|
||||||
);
|
);
|
||||||
|
@ -41,7 +41,7 @@ export function getSyncableElements(elements: readonly ExcalidrawElement[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getElementMap(elements: readonly ExcalidrawElement[]) {
|
export function getElementMap(elements: readonly ExcalidrawElement[]) {
|
||||||
return getSyncableElements(elements).reduce(
|
return elements.reduce(
|
||||||
(acc: { [key: string]: ExcalidrawElement }, element: ExcalidrawElement) => {
|
(acc: { [key: string]: ExcalidrawElement }, element: ExcalidrawElement) => {
|
||||||
acc[element.id] = element;
|
acc[element.id] = element;
|
||||||
return acc;
|
return acc;
|
||||||
|
@ -53,8 +53,8 @@ export function newElementWith<TElement extends ExcalidrawElement>(
|
|||||||
): TElement {
|
): TElement {
|
||||||
return {
|
return {
|
||||||
...element,
|
...element,
|
||||||
...updates,
|
|
||||||
version: element.version + 1,
|
version: element.version + 1,
|
||||||
versionNonce: randomSeed(),
|
versionNonce: randomSeed(),
|
||||||
|
...updates,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,41 @@ export class SceneHistory {
|
|||||||
) {
|
) {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
appState: clearAppStatePropertiesForHistory(appState),
|
appState: clearAppStatePropertiesForHistory(appState),
|
||||||
elements: elements.map(element => {
|
elements: elements.reduce((elements, element) => {
|
||||||
if (isLinearElement(element)) {
|
if (
|
||||||
return newElementWith(element, {
|
isLinearElement(element) &&
|
||||||
|
appState.multiElement &&
|
||||||
|
appState.multiElement.id === element.id
|
||||||
|
) {
|
||||||
|
// don't store multi-point arrow if still has only one point
|
||||||
|
if (
|
||||||
|
appState.multiElement &&
|
||||||
|
appState.multiElement.id === element.id &&
|
||||||
|
element.points.length < 2
|
||||||
|
) {
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.push(
|
||||||
|
newElementWith(element, {
|
||||||
|
// don't store last point if not committed
|
||||||
points:
|
points:
|
||||||
appState.multiElement && appState.multiElement.id === element.id
|
element.lastCommittedPoint !==
|
||||||
|
element.points[element.points.length - 1]
|
||||||
? element.points.slice(0, -1)
|
? element.points.slice(0, -1)
|
||||||
: element.points,
|
: element.points,
|
||||||
});
|
// don't regenerate versionNonce else this will short-circuit our
|
||||||
}
|
// bail-on-no-change logic in pushEntry()
|
||||||
return newElementWith(element, {});
|
versionNonce: element.versionNonce,
|
||||||
}),
|
}),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
elements.push(
|
||||||
|
newElementWith(element, { versionNonce: element.versionNonce }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return elements;
|
||||||
|
}, [] as Mutable<typeof elements>),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user