From fe65c1f1cca4e4082e5172649aff788d5a19b313 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 10 Nov 2023 06:56:02 -0800 Subject: [PATCH] Fix search terms for " and "" --- .../modules/placeable/components/Highlight.test.js | 14 ++++++++++++++ .../src/modules/placeable/components/Highlight.tsx | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/translate/src/modules/placeable/components/Highlight.test.js b/translate/src/modules/placeable/components/Highlight.test.js index 567f6aba40..6273c67068 100644 --- a/translate/src/modules/placeable/components/Highlight.test.js +++ b/translate/src/modules/placeable/components/Highlight.test.js @@ -121,6 +121,20 @@ describe('', () => { expect(marks.at(0).hasClass('search')); expect(marks.at(0).text()).toEqual('456'); }); + + it('does not break for lone " quotes', () => { + const wrapper = mountMarker('123456"', [], '"'); + const marks = wrapper.find('mark'); + expect(marks).toHaveLength(2); + expect(marks.at(1).text()).toEqual('"'); + }); + + it('does not break for doubled "" quotes', () => { + const wrapper = mountMarker('123456""', [], '""'); + const marks = wrapper.find('mark'); + expect(marks).toHaveLength(2); + expect(marks.at(1).text()).toEqual('""'); + }); }); describe('specific marker', () => { diff --git a/translate/src/modules/placeable/components/Highlight.tsx b/translate/src/modules/placeable/components/Highlight.tsx index 48c2257326..aa5e1b1cf1 100644 --- a/translate/src/modules/placeable/components/Highlight.tsx +++ b/translate/src/modules/placeable/components/Highlight.tsx @@ -168,14 +168,14 @@ export function Highlight({ if (search) { const searchTerms = search.match(/(?= 3 && term.endsWith('"')) { term = term.slice(1, -1); } let lcTerm = term.toLowerCase(); let pos = 0; let next: number; while ((next = lcSource.indexOf(lcTerm, pos)) !== -1) { - let i = marks.findIndex((m) => m.index + m.length >= next); + let i = marks.findIndex((m) => m.index + m.length > next); if (i === -1) { i = marks.length; }