From 326f733d4c06da4e0bcbf5182a8761c6ea745adb Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 18 Nov 2024 18:04:10 -0500 Subject: [PATCH] fix: Further improvements to diacritics matching in CMD+F --- app/editor/extensions/FindAndReplace.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/editor/extensions/FindAndReplace.tsx b/app/editor/extensions/FindAndReplace.tsx index 9cca9db143..98dbb87bb1 100644 --- a/app/editor/extensions/FindAndReplace.tsx +++ b/app/editor/extensions/FindAndReplace.tsx @@ -248,14 +248,19 @@ export default class FindAndReplaceExtension extends Extension { let m; const search = this.findRegExp; - while ((m = search.exec(deburr(text)))) { + // We construct a string with the text stripped of diacritics plus the original text for + // search allowing to search for diacritics-insensitive matches easily. + while ((m = search.exec(deburr(text) + text))) { if (m[0] === "") { break; } + // Reconstruct the correct match position + const i = m.index > text.length ? m.index - text.length : m.index; + this.results.push({ - from: pos + m.index, - to: pos + m.index + m[0].length, + from: pos + i, + to: pos + i + m[0].length, }); } } catch (e) {