From dfd176d791fef6152a222ed1077d58d36d6faf28 Mon Sep 17 00:00:00 2001 From: Josh Mu Date: Thu, 25 Apr 2024 15:24:38 +1000 Subject: [PATCH] feat: when no results show origin document --- src/periscope.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/periscope.ts b/src/periscope.ts index b3fa480..45080df 100644 --- a/src/periscope.ts +++ b/src/periscope.ts @@ -296,13 +296,10 @@ export const periscope = () => { return; } else if (code === 127) { const msg = `PERISCOPE: Ripgrep exited with code ${code} (Ripgrep not found. Please install ripgrep)`; - vscode.window.showErrorMessage(msg ); + vscode.window.showErrorMessage(msg); } else if (code === 1) { console.log(`PERISCOPE: Ripgrep exited with code ${code} (no results found)`); - if(!config.showPreviousResultsWhenNoMatches) { - // hide the previous results if no results found - qp.items = []; - } + handleNoResultsFound(); } else if (code === 2) { console.error(`PERISCOPE: Ripgrep exited with code ${code} (error during search operation)`); } else { @@ -314,6 +311,25 @@ export const periscope = () => { }); } + function handleNoResultsFound() { + if (config.showPreviousResultsWhenNoMatches) { + return; + } + + // hide the previous results if no results found + qp.items = []; + // no peek preview available, show the origin document instead + showPreviewOfOriginDocument(); + } + + function showPreviewOfOriginDocument() { + if (!previousActiveEditor) {return;} + vscode.window.showTextDocument(previousActiveEditor.document, { + preserveFocus: true, + preview: true + }); + } + function checkKillProcess() { spawnRegistry.forEach(spawnProcess => { spawnProcess.stdout.destroy();