From 83fde83a585d17656033a8f4b8cac50428c38527 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Fri, 24 Jul 2026 14:25:02 +0000 Subject: [PATCH] Preserve literal ordering for foreign source references --- internal/modules/dnd/shared/source_ref_order.go | 2 +- internal/modules/dnd/shared/source_ref_order_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/modules/dnd/shared/source_ref_order.go b/internal/modules/dnd/shared/source_ref_order.go index 5685788..c0395bb 100644 --- a/internal/modules/dnd/shared/source_ref_order.go +++ b/internal/modules/dnd/shared/source_ref_order.go @@ -38,7 +38,7 @@ func (o SourceRefOrder) Less(left, right source.SourceRef) bool { if lessEndpoint(positions, left.StartUnitID, right.StartUnitID) { return true } - if lessEndpoint(o.positions, right.StartUnitID, left.StartUnitID) { + if lessEndpoint(positions, right.StartUnitID, left.StartUnitID) { return false } return lessEndpoint(positions, left.EndUnitID, right.EndUnitID) diff --git a/internal/modules/dnd/shared/source_ref_order_test.go b/internal/modules/dnd/shared/source_ref_order_test.go index d5e8614..fd74d50 100644 --- a/internal/modules/dnd/shared/source_ref_order_test.go +++ b/internal/modules/dnd/shared/source_ref_order_test.go @@ -15,13 +15,13 @@ func TestSourceRefOrderUsesDocumentOrderAndLiteralFallbacks(t *testing.T) { {SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10}, {SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999}, {SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30}, - {SourceID: "other", StartUnitID: 20, EndUnitID: 20}, - {SourceID: "other", StartUnitID: 10, EndUnitID: 10}, + {SourceID: "other", StartUnitID: 30, EndUnitID: 1}, + {SourceID: "other", StartUnitID: 10, EndUnitID: 2}, } got := order.Canonicalize(refs) want := []source.SourceRef{ - {SourceID: "other", StartUnitID: 10, EndUnitID: 10}, - {SourceID: "other", StartUnitID: 20, EndUnitID: 20}, + {SourceID: "other", StartUnitID: 10, EndUnitID: 2}, + {SourceID: "other", StartUnitID: 30, EndUnitID: 1}, {SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30}, {SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10}, {SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999},