Skip to content

Commit c7a9e34

Browse files
authored
fix(search): include restored files in global search (#2830)
* fix(search): include restored files in global search * fix
1 parent 2a17db0 commit c7a9e34

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎src/sidebarApps/searchInFiles/index.js‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,10 @@ async function readSearchFileContent(uri) {
693693
if (helpers.isBinary(uri)) return "";
694694

695695
const editorFile = editorManager.getFile(uri, "uri");
696-
if (editorFile?.session?.doc) {
696+
const editorDocument = getSearchEditorDocument(editorFile);
697+
if (editorDocument) {
697698
try {
698-
return getDocText(editorFile.session.doc);
699+
return getDocText(editorDocument);
699700
} catch (_) {
700701
return "";
701702
}
@@ -704,6 +705,17 @@ async function readSearchFileContent(uri) {
704705
return fsOperation(uri).readFile(settings.value.defaultFileEncoding);
705706
}
706707

708+
function getSearchEditorDocument(file) {
709+
const document = file?.session?.doc;
710+
if (!document) return null;
711+
if (file.loaded) return document;
712+
713+
// Remote files can expose non-empty unsaved recovery text while their source
714+
// is still loading. An inactive restored tab instead has an empty placeholder.
715+
if (file.loading && file.isUnsaved && document.length > 0) return document;
716+
return null;
717+
}
718+
707719
function supportsNativeSearch(url = "") {
708720
return (
709721
fileIndex.supports(url) &&
@@ -819,9 +831,10 @@ function getOpenFileOverlays() {
819831
const overlays = {};
820832
editorManager.files.forEach((file) => {
821833
if (!file.uri || !supportsNativeSearch(file.uri)) return;
822-
if (!file.session?.doc) return;
834+
const editorDocument = getSearchEditorDocument(file);
835+
if (!editorDocument) return;
823836
try {
824-
overlays[file.uri] = getDocText(file.session.doc);
837+
overlays[file.uri] = getDocText(editorDocument);
825838
} catch (_) {
826839
// ignore invalid editor docs
827840
}

0 commit comments

Comments
 (0)