@@ -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+
707719function 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