From f057071adc323e77ad7256680e0e0f6ee70acc92 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Mon, 9 May 2022 07:34:51 -0700 Subject: [PATCH] Fix issue where intervals where merged when they did not overlap due to a typo, also only add interval to merged list if it has overlapped and been merged (#1228) --- simplistic_editor/lib/replacements.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/simplistic_editor/lib/replacements.dart b/simplistic_editor/lib/replacements.dart index a9403d5c2..e0ccd135b 100644 --- a/simplistic_editor/lib/replacements.dart +++ b/simplistic_editor/lib/replacements.dart @@ -603,12 +603,13 @@ class ReplacementTextEditingController extends TextEditingController { final List toRemoveRangesThatHaveBeenMerged = []; final List toAddRangesThatHaveBeenMerged = []; for (int i = 0; i < overlappingTriples.length; i++) { + bool didOverlap = false; List tripleA = overlappingTriples[i]; if (toRemoveRangesThatHaveBeenMerged.contains(tripleA)) continue; for (int j = i + 1; j < overlappingTriples.length; j++) { final List tripleB = overlappingTriples[j]; if (math.max(tripleA[0] as int, tripleB[0] as int) - <= math.min(tripleB[1] as int, tripleB[1] as int) + <= math.min(tripleA[1] as int, tripleB[1] as int) && tripleA[2] == tripleB[2]) { toRemoveRangesThatHaveBeenMerged.addAll([tripleA, tripleB]); tripleA = [ @@ -616,10 +617,11 @@ class ReplacementTextEditingController extends TextEditingController { math.max(tripleA[1] as int, tripleB[1] as int), tripleA[2], ]; + didOverlap = true; } } - if (i != overlappingTriples.length - 1 + if (didOverlap && !toAddRangesThatHaveBeenMerged.contains(tripleA) && !toRemoveRangesThatHaveBeenMerged.contains(tripleA)) { toAddRangesThatHaveBeenMerged.add(tripleA);