@@ -128,17 +128,16 @@ export async function importFile(
128128 ignoreConflict
129129 ) ;
130130 workspaceState . update ( `${ file . uniqueId } :mtime` , Number ( new Date ( data . result . ts + "Z" ) ) ) ;
131- if ( data . result . flag === "1" ) {
132- // putDoc returns new Storage definitions and the file must be a CLS
133- let content : string [ ] ;
134- ( content = new TextDecoder ( "utf-8" ) . decode ( await vscode . workspace . fs . readFile ( file . uri ) ) . split ( / \r ? \n / g) ) ,
135- ( content = updateStorage ( content , data . result . content ) ) ;
136- await vscode . workspace . fs . writeFile (
137- file . uri ,
138- new TextEncoder ( ) . encode (
139- content . join ( ( ( < CurrentTextFile > file ) ?. eol ?? vscode . EndOfLine . LF ) == vscode . EndOfLine . CRLF ? "\r\n" : "\n" )
140- )
141- ) ;
131+ if ( data . result . flags === 1 ) {
132+ // If flags === 1, putDoc returns new Storage definitions and the file must be a CLS
133+ const oldContent = new TextDecoder ( "utf-8" ) . decode ( await vscode . workspace . fs . readFile ( file . uri ) ) ;
134+ const oldContentArray = oldContent . split ( / \r ? \n / g) ;
135+ const newContentArray = updateStorage ( oldContentArray , data . result . content ) ;
136+ if ( oldContentArray . some ( ( oldLine , index ) => oldLine !== newContentArray [ index ] ) ) {
137+ const EOL = ( ( < CurrentTextFile > file ) ?. eol ?? vscode . EndOfLine . LF ) == vscode . EndOfLine . CRLF ? "\r\n" : "\n" ;
138+ const newContent = newContentArray . join ( EOL ) ;
139+ await vscode . workspace . fs . writeFile ( file . uri , new TextEncoder ( ) . encode ( newContent ) ) ;
140+ }
142141 }
143142 // In case another extension has used an 'objectscript://' uri to load a document read-only from the server,
144143 // make it reload with what we just imported to the server.
0 commit comments