Skip to content

Commit f519acb

Browse files
authored
ENG-1153 maximum update limit error on canvas after adding supports relation between evd and clm (#628)
* eng-1153: Exclude all arrow siblings, including relations in DiscourseRelationsBindings:reparentArrow. Also: use arrow literal instead of `arrow.type`
1 parent 7a7469c commit f519acb

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationBindings.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
removeArrowBinding,
3232
} from "./helpers";
3333
import { AddReferencedNodeType } from "./DiscourseRelationTool";
34+
import getDiscourseRelations from "~/utils/getDiscourseRelations";
3435

3536
export const createAllReferencedNodeBindings = (
3637
allAddReferencedNodeByAction: AddReferencedNodeType,
@@ -229,29 +230,30 @@ function reparentArrow(editor: Editor, arrowId: TLShapeId) {
229230

230231
let finalIndex: IndexKey;
231232

233+
const relationIds = new Set(getDiscourseRelations().map((r) => r.id));
234+
relationIds.add("arrow");
235+
236+
// if the next sibling is also a bound arrow though, we can end up
237+
// all fighting for the same indexes. so lets find the next
238+
// siblings which are not arrows or relations
232239
const higherSiblings = editor
233240
.getSortedChildIdsForParent(highestSibling.parentId)
234241
.map((id) => editor.getShape(id)!)
235-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
236-
.filter((sibling) => sibling.index > highestSibling!.index);
242+
.filter(
243+
(sibling) =>
244+
sibling.index > highestSibling.index && !relationIds.has(sibling.type), // avoid fighting for the same index
245+
);
237246

238247
if (higherSiblings.length) {
239248
// there are siblings above the highest bound sibling, we need to
240249
// insert between them.
241250

242-
// if the next sibling is also a bound arrow though, we can end up
243-
// all fighting for the same indexes. so lets find the next
244-
// non-arrow sibling...
245-
const nextHighestNonArrowSibling = higherSiblings.find(
246-
(sibling) => sibling.type !== arrow.type,
247-
);
248-
251+
const nextHighestNonArrowSibling = higherSiblings[0];
249252
if (
250253
// ...then, if we're above the last shape we want to be above...
251254
reparentedArrow.index > highestSibling.index &&
252255
// ...but below the next non-arrow sibling...
253-
(!nextHighestNonArrowSibling ||
254-
reparentedArrow.index < nextHighestNonArrowSibling.index)
256+
reparentedArrow.index < nextHighestNonArrowSibling.index
255257
) {
256258
// ...then we're already in the right place. no need to update!
257259
return;
@@ -260,7 +262,10 @@ function reparentArrow(editor: Editor, arrowId: TLShapeId) {
260262
// otherwise, we need to find the index between the highest sibling
261263
// we want to be above, and the next highest sibling we want to be
262264
// below:
263-
finalIndex = getIndexBetween(highestSibling.index, higherSiblings[0].index);
265+
finalIndex = getIndexBetween(
266+
highestSibling.index,
267+
nextHighestNonArrowSibling.index,
268+
);
264269
} else {
265270
// if there are no siblings above us, we can just get the next index:
266271
finalIndex = getIndexAbove(highestSibling.index);

0 commit comments

Comments
 (0)