From bb58c123060d293af73e9c40f9f0548f0989cfa5 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 13 Feb 2026 16:46:25 -0700 Subject: [PATCH] fix: Correct match offset when ignoring diacritics Co-authored-by: aider (gemini/gemini-2.5-pro) --- src/tools/text-processing.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/tools/text-processing.ts b/src/tools/text-processing.ts index 1f16c16..b9ea0f0 100644 --- a/src/tools/text-processing.ts +++ b/src/tools/text-processing.ts @@ -84,9 +84,16 @@ export class TextProcessor { } const matchStartIndex = match.index const matchEndIndex = matchStartIndex + match[0].length - const originalMatch = originalText - .substring(matchStartIndex, matchEndIndex) - .trim() + + // If `ignoreDiacritics` is on, `text` may have a different length than `originalText`, + // making `match.index` unreliable for `originalText`. + // We use `match[0]`, which is the matched term (but without diacritics). + const originalMatchBeforeTrim = this.plugin.settings.ignoreDiacritics + ? match[0] + : originalText.substring(matchStartIndex, matchEndIndex) + + const originalMatch = originalMatchBeforeTrim.trim() + if (originalMatch && match.index >= 0) { matches.push({ match: originalMatch, offset: match.index }) }