mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: proper deletion & sync of multi-point elements
- Fixed synchronization issue for multi-point elements - Updated version checks in shouldDiscardRemoteElement
This commit is contained in:
parent
192c4e7658
commit
381f3ac70e
3 changed files with 28 additions and 12 deletions
|
@ -105,10 +105,13 @@ export const actionFinalize = register({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInvisiblySmallElement(multiPointElement)) {
|
if (
|
||||||
|
multiPointElement.points.length < 2 ||
|
||||||
|
isInvisiblySmallElement(multiPointElement)
|
||||||
|
) {
|
||||||
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
||||||
newElements = newElements.filter(
|
newElements = newElements.map((el) =>
|
||||||
(el) => el.id !== multiPointElement.id,
|
el.id === multiPointElement.id ? { ...el, isDeleted: true } : el,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,17 +29,27 @@ const shouldDiscardRemoteElement = (
|
||||||
local &&
|
local &&
|
||||||
// local element is being edited
|
// local element is being edited
|
||||||
(local.id === localAppState.editingTextElement?.id ||
|
(local.id === localAppState.editingTextElement?.id ||
|
||||||
local.id === localAppState.resizingElement?.id ||
|
local.id === localAppState.resizingElement?.id)
|
||||||
local.id === localAppState.newElement?.id || // TODO: Is this still valid? As newElement is selection element, which is never part of the elements array
|
|
||||||
// local element is newer
|
|
||||||
local.version > remote.version ||
|
|
||||||
// resolve conflicting edits deterministically by taking the one with
|
|
||||||
// the lowest versionNonce
|
|
||||||
(local.version === remote.version &&
|
|
||||||
local.versionNonce < remote.versionNonce))
|
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (local?.version !== undefined && remote.version !== undefined) {
|
||||||
|
if (remote.isDeleted && remote.version > local.version) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (local.isDeleted && !remote.isDeleted) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local.version > remote.version) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (local.version === remote.version) {
|
||||||
|
return local.versionNonce < remote.versionNonce;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -522,7 +522,10 @@ export const restoreElements = (
|
||||||
(elements || []).reduce((elements, element) => {
|
(elements || []).reduce((elements, element) => {
|
||||||
// filtering out selection, which is legacy, no longer kept in elements,
|
// filtering out selection, which is legacy, no longer kept in elements,
|
||||||
// and causing issues if retained
|
// and causing issues if retained
|
||||||
if (element.type !== "selection" && !isInvisiblySmallElement(element)) {
|
if (
|
||||||
|
element.type !== "selection" &&
|
||||||
|
(!isInvisiblySmallElement(element) || element.isDeleted)
|
||||||
|
) {
|
||||||
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
||||||
if (migratedElement) {
|
if (migratedElement) {
|
||||||
const localElement = localElementsMap?.get(element.id);
|
const localElement = localElementsMap?.get(element.id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue