3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import { localize } from 'vs/nls' ;
6
7
import { Emitter } from 'vs/base/common/event' ;
7
8
import { URI } from 'vs/base/common/uri' ;
8
9
import { assertIsDefined , withNullAsUndefined } from 'vs/base/common/types' ;
9
10
import { EncodingMode , ITextFileService , TextFileEditorModelState , ITextFileEditorModel , ITextFileStreamContent , ITextFileResolveOptions , IResolvedTextFileEditorModel , ITextFileSaveOptions , TextFileResolveReason , ITextFileEditorModelSaveEvent } from 'vs/workbench/services/textfile/common/textfiles' ;
10
- import { IRevertOptions , SaveReason } from 'vs/workbench/common/editor' ;
11
+ import { IRevertOptions , SaveReason , SaveSourceRegistry } from 'vs/workbench/common/editor' ;
11
12
import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel' ;
12
13
import { IWorkingCopyBackupService , IResolvedWorkingCopyBackup } from 'vs/workbench/services/workingCopy/common/workingCopyBackup' ;
13
14
import { IFileService , FileOperationError , FileOperationResult , FileChangesEvent , FileChangeType , IFileStatWithMetadata , ETAG_DISABLED , FileSystemProviderCapabilities , NotModifiedSinceFileOperationError } from 'vs/platform/files/common/files' ;
@@ -46,6 +47,8 @@ interface IBackupMetaData extends IWorkingCopyBackupMeta {
46
47
*/
47
48
export class TextFileEditorModel extends BaseTextEditorModel implements ITextFileEditorModel {
48
49
50
+ private static readonly TEXTFILE_SAVE_ENCODING_SOURCE = SaveSourceRegistry . registerSource ( 'textFileEncoding.source' , localize ( 'textFileCreate.source' , "File Encoding Changed" ) ) ;
51
+
49
52
//#region Events
50
53
51
54
private readonly _onDidChangeContent = this . _register ( new Emitter < void > ( ) ) ;
@@ -1010,14 +1013,10 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
1010
1013
return ; // return early if encoding is invalid or did not change
1011
1014
}
1012
1015
1013
- if ( this . isDirty ( ) || this . inConflictMode ) {
1016
+ if ( this . isDirty ( ) ) {
1014
1017
return ; // return early to prevent accident saves in this case
1015
1018
}
1016
1019
1017
- if ( ! this . isResolved ( ) ) {
1018
- return ; // return early to prevent race with resolving
1019
- }
1020
-
1021
1020
// Re-open with new encoding
1022
1021
await this . setEncoding ( encoding , EncodingMode . Decode ) ;
1023
1022
}
@@ -1027,9 +1026,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
1027
1026
}
1028
1027
1029
1028
async setEncoding ( encoding : string , mode : EncodingMode ) : Promise < void > {
1030
- if ( ! this . isNewEncoding ( encoding ) ) {
1031
- return ; // return early if the encoding is already the same
1032
- }
1033
1029
1034
1030
// Encode: Save with encoding
1035
1031
if ( mode === EncodingMode . Encode ) {
@@ -1042,13 +1038,17 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
1042
1038
}
1043
1039
1044
1040
if ( ! this . inConflictMode ) {
1045
- await this . save ( ) ;
1041
+ await this . save ( { source : TextFileEditorModel . TEXTFILE_SAVE_ENCODING_SOURCE } ) ;
1046
1042
}
1047
1043
}
1048
1044
1049
1045
// Decode: Resolve with encoding
1050
1046
else {
1051
- if ( this . isDirty ( ) ) {
1047
+ if ( ! this . isNewEncoding ( encoding ) ) {
1048
+ return ; // return early if the encoding is already the same
1049
+ }
1050
+
1051
+ if ( this . isDirty ( ) && ! this . inConflictMode ) {
1052
1052
await this . save ( ) ;
1053
1053
}
1054
1054
0 commit comments