@@ -612,39 +612,55 @@ export default class EditorFile {
612612 const protocol = Url . getProtocol ( this . #uri) ;
613613 const text = this . session . getValue ( ) ;
614614
615+ // Helper for JS-based comparison (used as fallback)
616+ const jsCompare = async ( fileUri ) => {
617+ const fs = fsOperation ( fileUri ) ;
618+ const oldText = await fs . readFile ( this . encoding ) ;
619+ return await system . compareTexts ( oldText , text ) ;
620+ } ;
621+
615622 if ( / s ? f t p : / . test ( protocol ) ) {
616- // if file is a ftp or sftp file, get file content from cached file.
617- // remove ':' from protocol because cache file of remote files are
618- // stored as ftp102525465N i.e. protocol + id
619- // Cache files are local file:// URIs, so native file reading works
623+ // FTP/SFTP files use cached local file
620624 const cacheFilename = protocol . slice ( 0 , - 1 ) + this . id ;
621625 const cacheFileUri = Url . join ( CACHE_STORAGE , cacheFilename ) ;
622626
623627 try {
624628 return await system . compareFileText ( cacheFileUri , this . encoding , text ) ;
625629 } catch ( error ) {
626- console . error ( "Native compareFileText failed:" , error ) ;
627- return false ;
630+ console . error (
631+ "Native compareFileText failed, using JS fallback:" ,
632+ error ,
633+ ) ;
634+ try {
635+ return await jsCompare ( cacheFileUri ) ;
636+ } catch ( fallbackError ) {
637+ console . error ( fallbackError ) ;
638+ return false ;
639+ }
628640 }
629641 }
630642
631643 if ( / ^ ( f i l e | c o n t e n t ) : / . test ( protocol ) ) {
632- // file:// and content:// URIs can be handled by native Android code
633- // Native reads file AND compares in background thread
644+ // file:// and content:// URIs - try native first, fallback to JS
634645 try {
635646 return await system . compareFileText ( this . uri , this . encoding , text ) ;
636647 } catch ( error ) {
637- console . error ( "Native compareFileText failed:" , error ) ;
638- return false ;
648+ console . error (
649+ "Native compareFileText failed, using JS fallback:" ,
650+ error ,
651+ ) ;
652+ try {
653+ return await jsCompare ( this . uri ) ;
654+ } catch ( fallbackError ) {
655+ console . error ( fallbackError ) ;
656+ return false ;
657+ }
639658 }
640659 }
641660
661+ // Other protocols - JS reads file, native compares strings
642662 try {
643- const fs = fsOperation ( this . uri ) ;
644- const oldText = await fs . readFile ( this . encoding ) ;
645-
646- // Offload string comparison to background thread
647- return await system . compareTexts ( oldText , text ) ;
663+ return await jsCompare ( this . uri ) ;
648664 } catch ( error ) {
649665 console . error ( error ) ;
650666 return false ;
0 commit comments