account for widget span automatical matches when getting match by text by offset

This commit is contained in:
ggurdin 2025-11-05 15:08:04 -05:00
parent 5829c3e1ca
commit b285ffed88
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
2 changed files with 16 additions and 6 deletions

View file

@ -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#

View file

@ -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(