@codingame/monaco-vscode-api 1.83.15-next.0 → 1.83.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-api",
3
- "version": "1.83.15-next.0",
3
+ "version": "1.83.15",
4
4
  "description": "VSCode public API plugged on the monaco editor",
5
5
  "keywords": [],
6
6
  "author": {
@@ -100,10 +100,10 @@
100
100
  "dependencies": {
101
101
  "monaco-editor": "0.44.0",
102
102
  "vscode-semver": "npm:semver@=5.5.0",
103
- "@codingame/monaco-vscode-extensions-service-override": "1.83.15-next.0",
104
- "@codingame/monaco-vscode-files-service-override": "1.83.15-next.0",
105
- "@codingame/monaco-vscode-layout-service-override": "1.83.15-next.0",
106
- "@codingame/monaco-vscode-environment-service-override": "1.83.15-next.0",
107
- "@codingame/monaco-vscode-quickaccess-service-override": "1.83.15-next.0"
103
+ "@codingame/monaco-vscode-files-service-override": "1.83.15",
104
+ "@codingame/monaco-vscode-layout-service-override": "1.83.15",
105
+ "@codingame/monaco-vscode-environment-service-override": "1.83.15",
106
+ "@codingame/monaco-vscode-extensions-service-override": "1.83.15",
107
+ "@codingame/monaco-vscode-quickaccess-service-override": "1.83.15"
108
108
  }
109
109
  }
@@ -1,12 +1,18 @@
1
1
  import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
2
  import * as nls from 'monaco-editor/esm/vs/nls.js';
3
3
  import './media/dirtydiffDecorator.css.js';
4
- import { Disposable, DisposableStore, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
5
- import { Event } from 'monaco-editor/esm/vs/base/common/event.js';
4
+ import { ThrottledDelayer } from 'monaco-editor/esm/vs/base/common/async.js';
5
+ import { Disposable, DisposableStore, toDisposable, dispose } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
6
+ import { Event, Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
6
7
  import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
8
+ import { ITextModelService } from 'monaco-editor/esm/vs/editor/common/services/resolverService.js';
9
+ import { IEditorWorkerService } from 'monaco-editor/esm/vs/editor/common/services/editorWorker.js';
7
10
  import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
8
- import { IThemeService } from 'monaco-editor/esm/vs/platform/theme/common/themeService.js';
11
+ import { ISCMService } from '../common/scm.js';
12
+ import { ModelDecorationOptions } from 'monaco-editor/esm/vs/editor/common/model/textModel.js';
13
+ import { IThemeService, themeColorFromId } from 'monaco-editor/esm/vs/platform/theme/common/themeService.js';
9
14
  import { registerColor, editorErrorForeground, transparent } from 'monaco-editor/esm/vs/platform/theme/common/colorRegistry.js';
15
+ import { isCodeEditor } from 'monaco-editor/esm/vs/editor/browser/editorBrowser.js';
10
16
  import { registerEditorAction, registerEditorContribution, EditorAction } from 'monaco-editor/esm/vs/editor/browser/editorExtensions.js';
11
17
  import { getOuterEditor, PeekViewWidget, peekViewBorder, peekViewTitleBackground, peekViewTitleForeground, peekViewTitleInfoForeground } from 'monaco-editor/esm/vs/editor/contrib/peekView/browser/peekView.js';
12
18
  import { ContextKeyExpr, RawContextKey, IContextKeyService } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
@@ -20,17 +26,25 @@ import { IKeybindingService } from 'monaco-editor/esm/vs/platform/keybinding/com
20
26
  import { basename } from 'monaco-editor/esm/vs/base/common/resources.js';
21
27
  import { MenuRegistry, MenuId, IMenuService, MenuItemAction } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
22
28
  import { createAndFillInActionBarActions } from 'monaco-editor/esm/vs/platform/actions/browser/menuEntryActionViewItem.js';
29
+ import { shouldSynchronizeModel, OverviewRulerLane, MinimapPosition } from 'monaco-editor/esm/vs/editor/common/model.js';
30
+ import { sortedDiff, equals } from 'monaco-editor/esm/vs/base/common/arrays.js';
23
31
  import { ICodeEditorService } from 'monaco-editor/esm/vs/editor/browser/services/codeEditorService.js';
24
32
  import * as dom from 'monaco-editor/esm/vs/base/browser/dom.js';
33
+ import { isTextFileEditorModel, ITextFileService } from '../../../services/textfile/common/textfiles.js';
25
34
  import { gotoPreviousLocation, gotoNextLocation } from 'monaco-editor/esm/vs/platform/theme/common/iconRegistry.js';
26
35
  import { Codicon } from 'monaco-editor/esm/vs/base/common/codicons.js';
27
36
  import { ThemeIcon } from 'monaco-editor/esm/vs/base/common/themables.js';
37
+ import { onUnexpectedError } from 'monaco-editor/esm/vs/base/common/errors.js';
28
38
  import { TextCompareEditorActiveContext } from '../../../common/contextkeys.js';
39
+ import { IProgressService } from 'monaco-editor/esm/vs/platform/progress/common/progress.js';
29
40
  import { Color } from 'monaco-editor/esm/vs/base/common/color.js';
41
+ import { ResourceMap } from 'monaco-editor/esm/vs/base/common/map.js';
42
+ import { IEditorService } from '../../../services/editor/common/editorService.js';
30
43
  import { IAudioCueService, AudioCue } from 'monaco-editor/esm/vs/platform/audioCues/browser/audioCueService.js';
31
44
  import { IAccessibilityService } from 'monaco-editor/esm/vs/platform/accessibility/common/accessibility.js';
45
+ import { IQuickDiffService } from '../common/quickDiff.js';
32
46
  import { SwitchQuickDiffViewItem, SwitchQuickDiffBaseAction } from './dirtyDiffSwitcher.js';
33
- var DirtyDiffController_1;
47
+ var DirtyDiffController_1, DirtyDiffDecorator_1;
34
48
  class DiffActionRunner extends ActionRunner {
35
49
  runAction(action, context) {
36
50
  if (action instanceof MenuItemAction) {
@@ -872,7 +886,7 @@ const editorGutterDeletedBackground = registerColor('editorGutter.deletedBackgro
872
886
  'editorGutterDeletedBackground',
873
887
  "Editor gutter background color for lines that are deleted."
874
888
  )));
875
- registerColor('minimapGutter.modifiedBackground', {
889
+ const minimapGutterModifiedBackground = registerColor('minimapGutter.modifiedBackground', {
876
890
  dark: editorGutterModifiedBackground,
877
891
  light: editorGutterModifiedBackground,
878
892
  hcDark: editorGutterModifiedBackground,
@@ -882,7 +896,7 @@ registerColor('minimapGutter.modifiedBackground', {
882
896
  'minimapGutterModifiedBackground',
883
897
  "Minimap gutter background color for lines that are modified."
884
898
  )));
885
- registerColor('minimapGutter.addedBackground', {
899
+ const minimapGutterAddedBackground = registerColor('minimapGutter.addedBackground', {
886
900
  dark: editorGutterAddedBackground,
887
901
  light: editorGutterAddedBackground,
888
902
  hcDark: editorGutterAddedBackground,
@@ -892,7 +906,7 @@ registerColor('minimapGutter.addedBackground', {
892
906
  'minimapGutterAddedBackground',
893
907
  "Minimap gutter background color for lines that are added."
894
908
  )));
895
- registerColor('minimapGutter.deletedBackground', {
909
+ const minimapGutterDeletedBackground = registerColor('minimapGutter.deletedBackground', {
896
910
  dark: editorGutterDeletedBackground,
897
911
  light: editorGutterDeletedBackground,
898
912
  hcDark: editorGutterDeletedBackground,
@@ -902,24 +916,563 @@ registerColor('minimapGutter.deletedBackground', {
902
916
  'minimapGutterDeletedBackground',
903
917
  "Minimap gutter background color for lines that are deleted."
904
918
  )));
905
- registerColor('editorOverviewRuler.modifiedForeground', { dark: ( transparent(editorGutterModifiedBackground, 0.6)), light: ( transparent(editorGutterModifiedBackground, 0.6)), hcDark: ( transparent(editorGutterModifiedBackground, 0.6)), hcLight: ( transparent(editorGutterModifiedBackground, 0.6)) }, ( nls.localizeWithPath(
919
+ const overviewRulerModifiedForeground = registerColor('editorOverviewRuler.modifiedForeground', { dark: ( transparent(editorGutterModifiedBackground, 0.6)), light: ( transparent(editorGutterModifiedBackground, 0.6)), hcDark: ( transparent(editorGutterModifiedBackground, 0.6)), hcLight: ( transparent(editorGutterModifiedBackground, 0.6)) }, ( nls.localizeWithPath(
906
920
  'vs/workbench/contrib/scm/browser/dirtydiffDecorator',
907
921
  'overviewRulerModifiedForeground',
908
922
  'Overview ruler marker color for modified content.'
909
923
  )));
910
- registerColor('editorOverviewRuler.addedForeground', { dark: ( transparent(editorGutterAddedBackground, 0.6)), light: ( transparent(editorGutterAddedBackground, 0.6)), hcDark: ( transparent(editorGutterAddedBackground, 0.6)), hcLight: ( transparent(editorGutterAddedBackground, 0.6)) }, ( nls.localizeWithPath(
924
+ const overviewRulerAddedForeground = registerColor('editorOverviewRuler.addedForeground', { dark: ( transparent(editorGutterAddedBackground, 0.6)), light: ( transparent(editorGutterAddedBackground, 0.6)), hcDark: ( transparent(editorGutterAddedBackground, 0.6)), hcLight: ( transparent(editorGutterAddedBackground, 0.6)) }, ( nls.localizeWithPath(
911
925
  'vs/workbench/contrib/scm/browser/dirtydiffDecorator',
912
926
  'overviewRulerAddedForeground',
913
927
  'Overview ruler marker color for added content.'
914
928
  )));
915
- registerColor('editorOverviewRuler.deletedForeground', { dark: ( transparent(editorGutterDeletedBackground, 0.6)), light: ( transparent(editorGutterDeletedBackground, 0.6)), hcDark: ( transparent(editorGutterDeletedBackground, 0.6)), hcLight: ( transparent(editorGutterDeletedBackground, 0.6)) }, ( nls.localizeWithPath(
929
+ const overviewRulerDeletedForeground = registerColor('editorOverviewRuler.deletedForeground', { dark: ( transparent(editorGutterDeletedBackground, 0.6)), light: ( transparent(editorGutterDeletedBackground, 0.6)), hcDark: ( transparent(editorGutterDeletedBackground, 0.6)), hcLight: ( transparent(editorGutterDeletedBackground, 0.6)) }, ( nls.localizeWithPath(
916
930
  'vs/workbench/contrib/scm/browser/dirtydiffDecorator',
917
931
  'overviewRulerDeletedForeground',
918
932
  'Overview ruler marker color for deleted content.'
919
933
  )));
934
+ let DirtyDiffDecorator = DirtyDiffDecorator_1 = class DirtyDiffDecorator extends Disposable {
935
+ static createDecoration(className, options) {
936
+ const decorationOptions = {
937
+ description: 'dirty-diff-decoration',
938
+ isWholeLine: options.isWholeLine,
939
+ };
940
+ if (options.gutter) {
941
+ decorationOptions.linesDecorationsClassName = `dirty-diff-glyph ${className}`;
942
+ }
943
+ if (options.overview.active) {
944
+ decorationOptions.overviewRuler = {
945
+ color: themeColorFromId(options.overview.color),
946
+ position: OverviewRulerLane.Left
947
+ };
948
+ }
949
+ if (options.minimap.active) {
950
+ decorationOptions.minimap = {
951
+ color: themeColorFromId(options.minimap.color),
952
+ position: MinimapPosition.Gutter
953
+ };
954
+ }
955
+ return ModelDecorationOptions.createDynamic(decorationOptions);
956
+ }
957
+ constructor(editorModel, codeEditor, model, configurationService) {
958
+ super();
959
+ this.codeEditor = codeEditor;
960
+ this.model = model;
961
+ this.configurationService = configurationService;
962
+ this.editorModel = editorModel;
963
+ const decorations = configurationService.getValue('scm.diffDecorations');
964
+ const gutter = decorations === 'all' || decorations === 'gutter';
965
+ const overview = decorations === 'all' || decorations === 'overview';
966
+ const minimap = decorations === 'all' || decorations === 'minimap';
967
+ this.addedOptions = DirtyDiffDecorator_1.createDecoration('dirty-diff-added', {
968
+ gutter,
969
+ overview: { active: overview, color: overviewRulerAddedForeground },
970
+ minimap: { active: minimap, color: minimapGutterAddedBackground },
971
+ isWholeLine: true
972
+ });
973
+ this.addedPatternOptions = DirtyDiffDecorator_1.createDecoration('dirty-diff-added-pattern', {
974
+ gutter,
975
+ overview: { active: overview, color: overviewRulerAddedForeground },
976
+ minimap: { active: minimap, color: minimapGutterAddedBackground },
977
+ isWholeLine: true
978
+ });
979
+ this.modifiedOptions = DirtyDiffDecorator_1.createDecoration('dirty-diff-modified', {
980
+ gutter,
981
+ overview: { active: overview, color: overviewRulerModifiedForeground },
982
+ minimap: { active: minimap, color: minimapGutterModifiedBackground },
983
+ isWholeLine: true
984
+ });
985
+ this.modifiedPatternOptions = DirtyDiffDecorator_1.createDecoration('dirty-diff-modified-pattern', {
986
+ gutter,
987
+ overview: { active: overview, color: overviewRulerModifiedForeground },
988
+ minimap: { active: minimap, color: minimapGutterModifiedBackground },
989
+ isWholeLine: true
990
+ });
991
+ this.deletedOptions = DirtyDiffDecorator_1.createDecoration('dirty-diff-deleted', {
992
+ gutter,
993
+ overview: { active: overview, color: overviewRulerDeletedForeground },
994
+ minimap: { active: minimap, color: minimapGutterDeletedBackground },
995
+ isWholeLine: false
996
+ });
997
+ this._register(configurationService.onDidChangeConfiguration(e => {
998
+ if (e.affectsConfiguration('scm.diffDecorationsGutterPattern')) {
999
+ this.onDidChange();
1000
+ }
1001
+ }));
1002
+ this._register(model.onDidChange(this.onDidChange, this));
1003
+ }
1004
+ onDidChange() {
1005
+ if (!this.editorModel) {
1006
+ return;
1007
+ }
1008
+ const pattern = this.configurationService.getValue('scm.diffDecorationsGutterPattern');
1009
+ const decorations = ( this.model.changes.map((labeledChange) => {
1010
+ const change = labeledChange.change;
1011
+ const changeType = getChangeType(change);
1012
+ const startLineNumber = change.modifiedStartLineNumber;
1013
+ const endLineNumber = change.modifiedEndLineNumber || startLineNumber;
1014
+ switch (changeType) {
1015
+ case ChangeType.Add:
1016
+ return {
1017
+ range: {
1018
+ startLineNumber: startLineNumber, startColumn: 1,
1019
+ endLineNumber: endLineNumber, endColumn: 1
1020
+ },
1021
+ options: pattern.added ? this.addedPatternOptions : this.addedOptions
1022
+ };
1023
+ case ChangeType.Delete:
1024
+ return {
1025
+ range: {
1026
+ startLineNumber: startLineNumber, startColumn: Number.MAX_VALUE,
1027
+ endLineNumber: startLineNumber, endColumn: Number.MAX_VALUE
1028
+ },
1029
+ options: this.deletedOptions
1030
+ };
1031
+ case ChangeType.Modify:
1032
+ return {
1033
+ range: {
1034
+ startLineNumber: startLineNumber, startColumn: 1,
1035
+ endLineNumber: endLineNumber, endColumn: 1
1036
+ },
1037
+ options: pattern.modified ? this.modifiedPatternOptions : this.modifiedOptions
1038
+ };
1039
+ }
1040
+ }));
1041
+ if (!this.decorationsCollection) {
1042
+ this.decorationsCollection = this.codeEditor.createDecorationsCollection(decorations);
1043
+ }
1044
+ else {
1045
+ this.decorationsCollection.set(decorations);
1046
+ }
1047
+ }
1048
+ dispose() {
1049
+ super.dispose();
1050
+ if (this.decorationsCollection) {
1051
+ this.decorationsCollection?.clear();
1052
+ }
1053
+ this.editorModel = null;
1054
+ this.decorationsCollection = undefined;
1055
+ }
1056
+ };
1057
+ DirtyDiffDecorator = DirtyDiffDecorator_1 = ( __decorate([
1058
+ ( __param(3, IConfigurationService))
1059
+ ], DirtyDiffDecorator));
1060
+ function compareChanges(a, b) {
1061
+ let result = a.modifiedStartLineNumber - b.modifiedStartLineNumber;
1062
+ if (result !== 0) {
1063
+ return result;
1064
+ }
1065
+ result = a.modifiedEndLineNumber - b.modifiedEndLineNumber;
1066
+ if (result !== 0) {
1067
+ return result;
1068
+ }
1069
+ result = a.originalStartLineNumber - b.originalStartLineNumber;
1070
+ if (result !== 0) {
1071
+ return result;
1072
+ }
1073
+ return a.originalEndLineNumber - b.originalEndLineNumber;
1074
+ }
920
1075
  async function getOriginalResource(quickDiffService, uri, language, isSynchronized) {
921
1076
  const quickDiffs = await quickDiffService.getQuickDiffs(uri, language, isSynchronized);
922
1077
  return quickDiffs.length > 0 ? quickDiffs[0].originalResource : null;
923
1078
  }
1079
+ let DirtyDiffModel = class DirtyDiffModel extends Disposable {
1080
+ get original() { return this._originalTextModels; }
1081
+ get changes() { return this._changes; }
1082
+ get mapChanges() { return this._mapChanges; }
1083
+ constructor(textFileModel, scmService, quickDiffService, editorWorkerService, configurationService, textModelResolverService, progressService) {
1084
+ super();
1085
+ this.scmService = scmService;
1086
+ this.quickDiffService = quickDiffService;
1087
+ this.editorWorkerService = editorWorkerService;
1088
+ this.configurationService = configurationService;
1089
+ this.textModelResolverService = textModelResolverService;
1090
+ this.progressService = progressService;
1091
+ this._quickDiffs = [];
1092
+ this._originalModels = ( new Map());
1093
+ this._originalTextModels = [];
1094
+ this.diffDelayer = ( new ThrottledDelayer(200));
1095
+ this.repositoryDisposables = ( new Set());
1096
+ this.originalModelDisposables = this._register(( new DisposableStore()));
1097
+ this._disposed = false;
1098
+ this._onDidChange = ( new Emitter());
1099
+ this.onDidChange = this._onDidChange.event;
1100
+ this._changes = [];
1101
+ this._mapChanges = ( new Map());
1102
+ this._model = textFileModel;
1103
+ this._register(textFileModel.textEditorModel.onDidChangeContent(() => this.triggerDiff()));
1104
+ this._register(Event.filter(configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('scm.diffDecorationsIgnoreTrimWhitespace') || e.affectsConfiguration('diffEditor.ignoreTrimWhitespace'))(this.triggerDiff, this));
1105
+ this._register(scmService.onDidAddRepository(this.onDidAddRepository, this));
1106
+ for (const r of scmService.repositories) {
1107
+ this.onDidAddRepository(r);
1108
+ }
1109
+ this._register(this._model.onDidChangeEncoding(() => {
1110
+ this.diffDelayer.cancel();
1111
+ this._quickDiffs = [];
1112
+ this._originalModels.clear();
1113
+ this._originalTextModels = [];
1114
+ this._quickDiffsPromise = undefined;
1115
+ this.setChanges([], ( new Map()));
1116
+ this.triggerDiff();
1117
+ }));
1118
+ this._register(this.quickDiffService.onDidChangeQuickDiffProviders(() => this.triggerDiff()));
1119
+ this.triggerDiff();
1120
+ }
1121
+ get quickDiffs() {
1122
+ return this._quickDiffs;
1123
+ }
1124
+ getDiffEditorModel(originalUri) {
1125
+ if (!( this._originalModels.has(originalUri))) {
1126
+ return;
1127
+ }
1128
+ const original = this._originalModels.get(originalUri);
1129
+ return {
1130
+ modified: this._model.textEditorModel,
1131
+ original: original.textEditorModel
1132
+ };
1133
+ }
1134
+ onDidAddRepository(repository) {
1135
+ const disposables = ( new DisposableStore());
1136
+ this.repositoryDisposables.add(disposables);
1137
+ disposables.add(toDisposable(() => this.repositoryDisposables.delete(disposables)));
1138
+ const onDidChange = Event.any(repository.provider.onDidChange, repository.provider.onDidChangeResources);
1139
+ disposables.add(onDidChange(this.triggerDiff, this));
1140
+ const onDidRemoveThis = Event.filter(this.scmService.onDidRemoveRepository, r => r === repository);
1141
+ disposables.add(onDidRemoveThis(() => dispose(disposables), null));
1142
+ this.triggerDiff();
1143
+ }
1144
+ triggerDiff() {
1145
+ if (!this.diffDelayer) {
1146
+ return Promise.resolve(null);
1147
+ }
1148
+ return this.diffDelayer
1149
+ .trigger(() => this.diff())
1150
+ .then((result) => {
1151
+ const originalModels = Array.from(( this._originalModels.values()));
1152
+ if (!result || this._disposed || this._model.isDisposed() || ( originalModels.some(originalModel => originalModel.isDisposed()))) {
1153
+ return;
1154
+ }
1155
+ if (originalModels.every(originalModel => originalModel.textEditorModel.getValueLength() === 0)) {
1156
+ result.changes = [];
1157
+ }
1158
+ if (!result.changes) {
1159
+ result.changes = [];
1160
+ }
1161
+ this.setChanges(result.changes, result.mapChanges);
1162
+ }, (err) => onUnexpectedError(err));
1163
+ }
1164
+ setChanges(changes, mapChanges) {
1165
+ const diff = sortedDiff(this._changes, changes, (a, b) => compareChanges(a.change, b.change));
1166
+ this._changes = changes;
1167
+ this._mapChanges = mapChanges;
1168
+ this._onDidChange.fire({ changes, diff });
1169
+ }
1170
+ diff() {
1171
+ return this.progressService.withProgress({ location: 3 , delay: 250 }, async () => {
1172
+ const originalURIs = await this.getQuickDiffsPromise();
1173
+ if (this._disposed || this._model.isDisposed() || (originalURIs.length === 0)) {
1174
+ return Promise.resolve({ changes: [], mapChanges: ( new Map()) });
1175
+ }
1176
+ const filteredToDiffable = originalURIs.filter(quickDiff => this.editorWorkerService.canComputeDirtyDiff(quickDiff.originalResource, this._model.resource));
1177
+ if (filteredToDiffable.length === 0) {
1178
+ return Promise.resolve({ changes: [], mapChanges: ( new Map()) });
1179
+ }
1180
+ const ignoreTrimWhitespaceSetting = this.configurationService.getValue('scm.diffDecorationsIgnoreTrimWhitespace');
1181
+ const ignoreTrimWhitespace = ignoreTrimWhitespaceSetting === 'inherit'
1182
+ ? this.configurationService.getValue('diffEditor.ignoreTrimWhitespace')
1183
+ : ignoreTrimWhitespaceSetting !== 'false';
1184
+ const allDiffs = [];
1185
+ for (const quickDiff of filteredToDiffable) {
1186
+ const dirtyDiff = await this.editorWorkerService.computeDirtyDiff(quickDiff.originalResource, this._model.resource, ignoreTrimWhitespace);
1187
+ if (dirtyDiff) {
1188
+ for (const diff of dirtyDiff) {
1189
+ if (diff) {
1190
+ allDiffs.push({ change: diff, label: quickDiff.label, uri: quickDiff.originalResource });
1191
+ }
1192
+ }
1193
+ }
1194
+ }
1195
+ const sorted = allDiffs.sort((a, b) => compareChanges(a.change, b.change));
1196
+ const map = ( new Map());
1197
+ for (let i = 0; i < sorted.length; i++) {
1198
+ const label = sorted[i].label;
1199
+ if (!( map.has(label))) {
1200
+ map.set(label, []);
1201
+ }
1202
+ map.get(label).push(i);
1203
+ }
1204
+ return { changes: sorted, mapChanges: map };
1205
+ });
1206
+ }
1207
+ getQuickDiffsPromise() {
1208
+ if (this._quickDiffsPromise) {
1209
+ return this._quickDiffsPromise;
1210
+ }
1211
+ this._quickDiffsPromise = this.getOriginalResource().then(async (quickDiffs) => {
1212
+ if (this._disposed) {
1213
+ return [];
1214
+ }
1215
+ if (quickDiffs.length === 0) {
1216
+ this._quickDiffs = [];
1217
+ this._originalModels.clear();
1218
+ this._originalTextModels = [];
1219
+ return [];
1220
+ }
1221
+ if (equals(this._quickDiffs, quickDiffs, (a, b) => ( a.originalResource.toString()) === ( b.originalResource.toString()) && a.label === b.label)) {
1222
+ return quickDiffs;
1223
+ }
1224
+ this.originalModelDisposables.clear();
1225
+ this._originalModels.clear();
1226
+ this._originalTextModels = [];
1227
+ this._quickDiffs = quickDiffs;
1228
+ return (await Promise.all(( quickDiffs.map(async (quickDiff) => {
1229
+ try {
1230
+ const ref = await this.textModelResolverService.createModelReference(quickDiff.originalResource);
1231
+ if (this._disposed) {
1232
+ ref.dispose();
1233
+ return [];
1234
+ }
1235
+ this._originalModels.set(( quickDiff.originalResource.toString()), ref.object);
1236
+ this._originalTextModels.push(ref.object.textEditorModel);
1237
+ if (isTextFileEditorModel(ref.object)) {
1238
+ const encoding = this._model.getEncoding();
1239
+ if (encoding) {
1240
+ ref.object.setEncoding(encoding, 1 );
1241
+ }
1242
+ }
1243
+ this.originalModelDisposables.add(ref);
1244
+ this.originalModelDisposables.add(ref.object.textEditorModel.onDidChangeContent(() => this.triggerDiff()));
1245
+ return quickDiff;
1246
+ }
1247
+ catch (error) {
1248
+ return [];
1249
+ }
1250
+ })))).flat();
1251
+ });
1252
+ return this._quickDiffsPromise.finally(() => {
1253
+ this._quickDiffsPromise = undefined;
1254
+ });
1255
+ }
1256
+ async getOriginalResource() {
1257
+ if (this._disposed) {
1258
+ return Promise.resolve([]);
1259
+ }
1260
+ const uri = this._model.resource;
1261
+ return this.quickDiffService.getQuickDiffs(uri, this._model.getLanguageId(), this._model.textEditorModel ? shouldSynchronizeModel(this._model.textEditorModel) : undefined);
1262
+ }
1263
+ findNextClosestChange(lineNumber, inclusive = true, provider) {
1264
+ let preferredProvider;
1265
+ if (!provider && inclusive) {
1266
+ preferredProvider = this.quickDiffs.find(value => value.isSCM)?.label;
1267
+ }
1268
+ const possibleChanges = [];
1269
+ for (let i = 0; i < this.changes.length; i++) {
1270
+ if (provider && this.changes[i].label !== provider) {
1271
+ continue;
1272
+ }
1273
+ const change = this.changes[i];
1274
+ const possibleChangesLength = possibleChanges.length;
1275
+ if (inclusive) {
1276
+ if (getModifiedEndLineNumber(change.change) >= lineNumber) {
1277
+ if (preferredProvider && change.label !== preferredProvider) {
1278
+ possibleChanges.push(i);
1279
+ }
1280
+ else {
1281
+ return i;
1282
+ }
1283
+ }
1284
+ }
1285
+ else {
1286
+ if (change.change.modifiedStartLineNumber > lineNumber) {
1287
+ return i;
1288
+ }
1289
+ }
1290
+ if ((possibleChanges.length > 0) && (possibleChanges.length === possibleChangesLength)) {
1291
+ return possibleChanges[0];
1292
+ }
1293
+ }
1294
+ return possibleChanges.length > 0 ? possibleChanges[0] : 0;
1295
+ }
1296
+ findPreviousClosestChange(lineNumber, inclusive = true, provider) {
1297
+ for (let i = this.changes.length - 1; i >= 0; i--) {
1298
+ if (provider && this.changes[i].label !== provider) {
1299
+ continue;
1300
+ }
1301
+ const change = this.changes[i].change;
1302
+ if (inclusive) {
1303
+ if (change.modifiedStartLineNumber <= lineNumber) {
1304
+ return i;
1305
+ }
1306
+ }
1307
+ else {
1308
+ if (getModifiedEndLineNumber(change) < lineNumber) {
1309
+ return i;
1310
+ }
1311
+ }
1312
+ }
1313
+ return this.changes.length - 1;
1314
+ }
1315
+ dispose() {
1316
+ super.dispose();
1317
+ this._disposed = true;
1318
+ this._quickDiffs = [];
1319
+ this._originalModels.clear();
1320
+ this._originalTextModels = [];
1321
+ this.diffDelayer.cancel();
1322
+ this.repositoryDisposables.forEach(d => dispose(d));
1323
+ this.repositoryDisposables.clear();
1324
+ }
1325
+ };
1326
+ DirtyDiffModel = ( __decorate([
1327
+ ( __param(1, ISCMService)),
1328
+ ( __param(2, IQuickDiffService)),
1329
+ ( __param(3, IEditorWorkerService)),
1330
+ ( __param(4, IConfigurationService)),
1331
+ ( __param(5, ITextModelService)),
1332
+ ( __param(6, IProgressService))
1333
+ ], DirtyDiffModel));
1334
+ class DirtyDiffItem {
1335
+ constructor(model, decorator) {
1336
+ this.model = model;
1337
+ this.decorator = decorator;
1338
+ }
1339
+ dispose() {
1340
+ this.decorator.dispose();
1341
+ this.model.dispose();
1342
+ }
1343
+ }
1344
+ let DirtyDiffWorkbenchController = class DirtyDiffWorkbenchController extends Disposable {
1345
+ constructor(editorService, instantiationService, configurationService, textFileService) {
1346
+ super();
1347
+ this.editorService = editorService;
1348
+ this.instantiationService = instantiationService;
1349
+ this.configurationService = configurationService;
1350
+ this.textFileService = textFileService;
1351
+ this.enabled = false;
1352
+ this.viewState = { width: 3, visibility: 'always' };
1353
+ this.items = ( new ResourceMap());
1354
+ this.transientDisposables = this._register(( new DisposableStore()));
1355
+ this.stylesheet = dom.createStyleSheet();
1356
+ this._register(toDisposable(() => this.stylesheet.parentElement.removeChild(this.stylesheet)));
1357
+ const onDidChangeConfiguration = Event.filter(configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('scm.diffDecorations'));
1358
+ this._register(onDidChangeConfiguration(this.onDidChangeConfiguration, this));
1359
+ this.onDidChangeConfiguration();
1360
+ const onDidChangeDiffWidthConfiguration = Event.filter(configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('scm.diffDecorationsGutterWidth'));
1361
+ onDidChangeDiffWidthConfiguration(this.onDidChangeDiffWidthConfiguration, this);
1362
+ this.onDidChangeDiffWidthConfiguration();
1363
+ const onDidChangeDiffVisibilityConfiguration = Event.filter(configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('scm.diffDecorationsGutterVisibility'));
1364
+ onDidChangeDiffVisibilityConfiguration(this.onDidChangeDiffVisibiltiyConfiguration, this);
1365
+ this.onDidChangeDiffVisibiltiyConfiguration();
1366
+ }
1367
+ onDidChangeConfiguration() {
1368
+ const enabled = this.configurationService.getValue('scm.diffDecorations') !== 'none';
1369
+ if (enabled) {
1370
+ this.enable();
1371
+ }
1372
+ else {
1373
+ this.disable();
1374
+ }
1375
+ }
1376
+ onDidChangeDiffWidthConfiguration() {
1377
+ let width = this.configurationService.getValue('scm.diffDecorationsGutterWidth');
1378
+ if (isNaN(width) || width <= 0 || width > 5) {
1379
+ width = 3;
1380
+ }
1381
+ this.setViewState({ ...this.viewState, width });
1382
+ }
1383
+ onDidChangeDiffVisibiltiyConfiguration() {
1384
+ const visibility = this.configurationService.getValue('scm.diffDecorationsGutterVisibility');
1385
+ this.setViewState({ ...this.viewState, visibility });
1386
+ }
1387
+ setViewState(state) {
1388
+ this.viewState = state;
1389
+ this.stylesheet.textContent = `
1390
+ .monaco-editor .dirty-diff-added,
1391
+ .monaco-editor .dirty-diff-modified {
1392
+ border-left-width:${state.width}px;
1393
+ }
1394
+ .monaco-editor .dirty-diff-added-pattern,
1395
+ .monaco-editor .dirty-diff-added-pattern:before,
1396
+ .monaco-editor .dirty-diff-modified-pattern,
1397
+ .monaco-editor .dirty-diff-modified-pattern:before {
1398
+ background-size: ${state.width}px ${state.width}px;
1399
+ }
1400
+ .monaco-editor .dirty-diff-added,
1401
+ .monaco-editor .dirty-diff-added-pattern,
1402
+ .monaco-editor .dirty-diff-modified,
1403
+ .monaco-editor .dirty-diff-modified-pattern,
1404
+ .monaco-editor .dirty-diff-deleted {
1405
+ opacity: ${state.visibility === 'always' ? 1 : 0};
1406
+ }
1407
+ `;
1408
+ }
1409
+ enable() {
1410
+ if (this.enabled) {
1411
+ this.disable();
1412
+ }
1413
+ this.transientDisposables.add(Event.any(this.editorService.onDidCloseEditor, this.editorService.onDidVisibleEditorsChange)(() => this.onEditorsChanged()));
1414
+ this.onEditorsChanged();
1415
+ this.enabled = true;
1416
+ }
1417
+ disable() {
1418
+ if (!this.enabled) {
1419
+ return;
1420
+ }
1421
+ this.transientDisposables.clear();
1422
+ for (const [, dirtyDiff] of this.items) {
1423
+ dispose(( dirtyDiff.values()));
1424
+ }
1425
+ this.items.clear();
1426
+ this.enabled = false;
1427
+ }
1428
+ onEditorsChanged() {
1429
+ for (const editor of this.editorService.visibleTextEditorControls) {
1430
+ if (isCodeEditor(editor)) {
1431
+ const textModel = editor.getModel();
1432
+ const controller = DirtyDiffController.get(editor);
1433
+ if (controller) {
1434
+ controller.modelRegistry = this;
1435
+ }
1436
+ if (textModel && (!( this.items.has(textModel.uri)) || !( this.items.get(textModel.uri).has(editor.getId())))) {
1437
+ const textFileModel = this.textFileService.files.get(textModel.uri);
1438
+ if (textFileModel?.isResolved()) {
1439
+ const dirtyDiffModel = this.instantiationService.createInstance(DirtyDiffModel, textFileModel);
1440
+ const decorator = ( new DirtyDiffDecorator(
1441
+ textFileModel.textEditorModel,
1442
+ editor,
1443
+ dirtyDiffModel,
1444
+ this.configurationService
1445
+ ));
1446
+ if (!( this.items.has(textModel.uri))) {
1447
+ this.items.set(textModel.uri, ( new Map()));
1448
+ }
1449
+ this.items.get(textModel.uri)?.set(editor.getId(), ( new DirtyDiffItem(dirtyDiffModel, decorator)));
1450
+ }
1451
+ }
1452
+ }
1453
+ }
1454
+ for (const [uri, item] of this.items) {
1455
+ for (const editorId of ( item.keys())) {
1456
+ if (!this.editorService.visibleTextEditorControls.find(editor => isCodeEditor(editor) && editor.getModel()?.uri.toString() === ( uri.toString()) && editor.getId() === editorId)) {
1457
+ dispose(( item.values()));
1458
+ this.items.delete(uri);
1459
+ }
1460
+ }
1461
+ }
1462
+ }
1463
+ getModel(editorModel, codeEditor) {
1464
+ return this.items.get(editorModel.uri)?.get(codeEditor.getId())?.model;
1465
+ }
1466
+ dispose() {
1467
+ this.disable();
1468
+ super.dispose();
1469
+ }
1470
+ };
1471
+ DirtyDiffWorkbenchController = ( __decorate([
1472
+ ( __param(0, IEditorService)),
1473
+ ( __param(1, IInstantiationService)),
1474
+ ( __param(2, IConfigurationService)),
1475
+ ( __param(3, ITextFileService))
1476
+ ], DirtyDiffWorkbenchController));
924
1477
  registerEditorContribution(DirtyDiffController.ID, DirtyDiffController, 1 );
925
- export { DirtyDiffController, GotoNextChangeAction, GotoPreviousChangeAction, ShowNextChangeAction, ShowPreviousChangeAction, getOriginalResource, isDirtyDiffVisible };
1478
+ export { DirtyDiffController, DirtyDiffModel, DirtyDiffWorkbenchController, GotoNextChangeAction, GotoPreviousChangeAction, ShowNextChangeAction, ShowPreviousChangeAction, getOriginalResource, isDirtyDiffVisible };