From 41f142ab0657e8fb8a9eb23a04cb240d8a99a4c8 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 13 May 2025 15:27:50 +0300 Subject: [PATCH] feat(code): re-trigger search after replace --- apps/client/src/widgets/find_in_code.ts | 29 ++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/client/src/widgets/find_in_code.ts b/apps/client/src/widgets/find_in_code.ts index a66683eee..5dc8536ba 100644 --- a/apps/client/src/widgets/find_in_code.ts +++ b/apps/client/src/widgets/find_in_code.ts @@ -17,10 +17,16 @@ interface Match { }; } +interface SearchParameters { + searchTerm: string; + matchCase: boolean; + wholeWord: boolean; +} + export default class FindInCode { private parent: FindWidget; - private findResult?: Match[] | null; + private searchParameters: SearchParameters | null = null; constructor(parent: FindWidget) { this.parent = parent; @@ -36,6 +42,11 @@ export default class FindInCode { return { totalFound: 0, currentFound: 0 }; } + this.searchParameters = { + searchTerm, + matchCase, + wholeWord, + }; const { totalFound, currentFound } = await codeEditor.performFind(searchTerm, matchCase, wholeWord); return { totalFound, currentFound }; } @@ -57,11 +68,23 @@ export default class FindInCode { async replace(replaceText: string) { const codeEditor = await this.getCodeEditor(); - codeEditor?.replace(replaceText); + await codeEditor?.replace(replaceText); + this.rerunSearch(); } async replaceAll(replaceText: string) { const codeEditor = await this.getCodeEditor(); - codeEditor?.replaceAll(replaceText); + await codeEditor?.replaceAll(replaceText); + this.rerunSearch(); } + + private rerunSearch() { + if (this.searchParameters) { + this.performFind( + this.searchParameters.searchTerm, + this.searchParameters.matchCase, + this.searchParameters.wholeWord); + } + } + }