From b285ffed8867b696d8a2c17ff0fb87b988fc2e28 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 5 Nov 2025 15:08:04 -0500 Subject: [PATCH] account for widget span automatical matches when getting match by text by offset --- lib/pages/chat/input_bar.dart | 20 ++++++++++++++----- .../choreographer/models/span_data.dart | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index f06e87639..283cb9d26 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -437,11 +437,21 @@ class InputBar extends StatelessWidget { return; } - choreographer.chatController.onSelectMatch( - choreographer.igcController.getMatchByOffset( - controller!.selection.baseOffset, - ), - ); + // Normalization matchs are widget spans that mess with offsets, + // so we need to adjust the offset accordingly + int adjustedOffset = controller!.selection.baseOffset; + final normalizationMatches = + choreographer.igcController.recentNormalizationMatches; + if (normalizationMatches == null || normalizationMatches.isEmpty) return; + for (final match in normalizationMatches) { + if (match.updatedMatch.match.offset < adjustedOffset && + match.updatedMatch.match.length > 0) { + adjustedOffset += (match.updatedMatch.match.length - 1); + } + } + + final match = choreographer.igcController.getMatchByOffset(adjustedOffset); + choreographer.chatController.onSelectMatch(match); } // Pangea# diff --git a/lib/pangea/choreographer/models/span_data.dart b/lib/pangea/choreographer/models/span_data.dart index e55ee212c..c5b0ebd32 100644 --- a/lib/pangea/choreographer/models/span_data.dart +++ b/lib/pangea/choreographer/models/span_data.dart @@ -85,7 +85,7 @@ class SpanData { }; bool isOffsetInMatchSpan(int offset) => - offset >= this.offset && offset < this.offset + length; + offset >= this.offset && offset <= this.offset + length; SpanChoice? get bestChoice { return choices?.firstWhereOrNull(