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();