Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/sidebarApps/searchInFiles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,10 @@ async function readSearchFileContent(uri) {
if (helpers.isBinary(uri)) return "";

const editorFile = editorManager.getFile(uri, "uri");
if (editorFile?.session?.doc) {
const editorDocument = getSearchEditorDocument(editorFile);
if (editorDocument) {
try {
return getDocText(editorFile.session.doc);
return getDocText(editorDocument);
} catch (_) {
return "";
}
Expand All @@ -704,6 +705,17 @@ async function readSearchFileContent(uri) {
return fsOperation(uri).readFile(settings.value.defaultFileEncoding);
}

function getSearchEditorDocument(file) {
const document = file?.session?.doc;
if (!document) return null;
if (file.loaded) return document;

// Remote files can expose non-empty unsaved recovery text while their source
// is still loading. An inactive restored tab instead has an empty placeholder.
if (file.loading && file.isUnsaved && document.length > 0) return document;
return null;
}

function supportsNativeSearch(url = "") {
return (
fileIndex.supports(url) &&
Expand Down Expand Up @@ -819,9 +831,10 @@ function getOpenFileOverlays() {
const overlays = {};
editorManager.files.forEach((file) => {
if (!file.uri || !supportsNativeSearch(file.uri)) return;
if (!file.session?.doc) return;
const editorDocument = getSearchEditorDocument(file);
if (!editorDocument) return;
try {
overlays[file.uri] = getDocText(file.session.doc);
overlays[file.uri] = getDocText(editorDocument);
} catch (_) {
// ignore invalid editor docs
}
Expand Down