@@ -31,6 +31,7 @@ import {
3131 removeArrowBinding ,
3232} from "./helpers" ;
3333import { AddReferencedNodeType } from "./DiscourseRelationTool" ;
34+ import getDiscourseRelations from "~/utils/getDiscourseRelations" ;
3435
3536export 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