@codingame/monaco-vscode-editor-api 2.1.4 → 2.2.0-next.1

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.
@@ -1,7 +1,7 @@
1
1
  import { ConfigurationChangedEvent, ApplyUpdateResult, EditorOptions } from 'vscode/vscode/vs/editor/common/config/editorOptions';
2
2
  import { createMonacoBaseAPI } from 'vscode/vscode/vs/editor/common/services/editorBaseApi';
3
3
  import { mainWindow } from 'vscode/vscode/vs/base/browser/window';
4
- import { Disposable, DisposableStore, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
4
+ import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
5
5
  import { startsWithUTF8BOM, splitLines } from 'vscode/vscode/vs/base/common/strings';
6
6
  import { URI } from 'vscode/vscode/vs/base/common/uri';
7
7
  import { FontMeasurements } from 'vscode/vscode/vs/editor/browser/config/fontMeasurements';
@@ -27,36 +27,13 @@ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/c
27
27
  import { StandaloneEditor, StandaloneDiffEditor2, createTextModel } from 'vscode/vscode/vs/editor/standalone/browser/standaloneCodeEditor';
28
28
  import { StandaloneServices, StandaloneKeybindingService } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
29
29
  import { IStandaloneThemeService } from 'vscode/vscode/vs/editor/standalone/common/standaloneTheme';
30
- import { MenuId, MenuRegistry } from 'vscode/vscode/vs/platform/actions/common/actions';
30
+ import { MenuRegistry, MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
31
31
  import { CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
32
- import { IContextKeyService, ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
32
+ import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
33
33
  import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
34
34
  import { IMarkerService } from 'vscode/vscode/vs/platform/markers/common/markers';
35
35
  import { IOpenerService } from 'vscode/vscode/vs/platform/opener/common/opener';
36
- import { ObservableElementSizeObserver, readHotReloadableExport } from 'vscode/vscode/vs/editor/browser/widget/diffEditor/utils';
37
- import { h, scheduleAtNextAnimationFrame, getWindow } from 'vscode/vscode/vs/base/browser/dom';
38
- import { SmoothScrollableElement } from 'vscode/vscode/vs/base/browser/ui/scrollbar/scrollableElement';
39
- import { findFirstMaxBy } from 'vscode/vscode/vs/base/common/arraysFind';
40
- import { observableValue, globalTransaction, transaction, disposableObservableValue } from 'vscode/vscode/vs/base/common/observableInternal/base';
41
- import { Scrollable } from 'vscode/vscode/vs/base/common/scrollable';
42
- import { OffsetRange } from 'vscode/vscode/vs/editor/common/core/offsetRange';
43
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
44
- import { Button } from 'vscode/vscode/vs/base/browser/ui/button/button';
45
- import { Codicon } from 'vscode/vscode/vs/base/common/codicons';
46
- import { DiffEditorWidget } from 'vscode/vscode/vs/editor/browser/widget/diffEditor/diffEditorWidget';
47
- import { MenuWorkbenchToolBar } from 'vscode/vscode/vs/platform/actions/browser/toolbar';
48
- import { ActionRunner } from 'vscode/vscode/vs/base/common/actions';
49
- import { derived, derivedWithStore } from 'vscode/vscode/vs/base/common/observableInternal/derived';
50
- import { autorun, autorunWithStore } from 'vscode/vscode/vs/base/common/observableInternal/autorun';
51
- import { observableFromEvent, derivedObservableWithCache, mapObservableArrayCached, recomputeInitiallyAndOnChange } from 'vscode/vscode/vs/base/common/observableInternal/utils';
52
- import { ServiceCollection } from 'vscode/vscode/vs/platform/instantiation/common/serviceCollection';
53
- import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
54
- import { Selection as Selection$1 } from 'vscode/vscode/vs/editor/common/core/selection';
55
- import { DiffEditorOptions } from 'vscode/vscode/vs/editor/browser/widget/diffEditor/diffEditorOptions';
56
- import { DiffEditorViewModel } from 'vscode/vscode/vs/editor/browser/widget/diffEditor/diffEditorViewModel';
57
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
58
- import { registerColor } from 'vscode/vscode/vs/platform/theme/common/colorRegistry';
59
- import { Event } from 'vscode/vscode/vs/base/common/event';
36
+ import { MultiDiffEditorWidget } from 'vscode/vscode/vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorWidget';
60
37
  import { Color } from 'vscode/vscode/vs/base/common/color';
61
38
  import { Range as Range$1 } from 'vscode/vscode/vs/editor/common/core/range';
62
39
  import { ILanguageFeaturesService } from 'vscode/vscode/vs/editor/common/services/languageFeatures';
@@ -1025,705 +1002,6 @@ function _actualColorize(lines, tabSize, tokenizationSupport, languageIdCodec) {
1025
1002
  return html.join('');
1026
1003
  }
1027
1004
 
1028
- var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=( Object.keys(r.attributes)),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
1029
-
1030
- var css = ".monaco-component.multiDiffEditor{background:var(--vscode-multiDiffEditor-background);overflow-y:hidden}.monaco-component .multiDiffEntry{border-bottom:1px solid var(--vscode-multiDiffEditor-border);display:flex;flex:1;flex-direction:column;overflow:hidden}.monaco-component .multiDiffEntry .collapse-button{cursor:pointer;margin:0 5px}.monaco-component .multiDiffEntry .collapse-button a{display:block}.monaco-component .multiDiffEntry .header{align-items:center;background:var(--vscode-editor-background);border-bottom:1px solid var(--vscode-sideBarSectionHeader-border);border-top:1px solid var(--vscode-multiDiffEditor-border);color:var(--vscode-foreground);display:flex;padding:8px 5px;z-index:1000}.monaco-component .multiDiffEntry .header.shadow{box-shadow:var(--vscode-scrollbar-shadow) 0 6px 6px -6px}.monaco-component .multiDiffEntry .header .file-path{display:flex;flex:1;min-width:0}.monaco-component .multiDiffEntry .header .file-path .title{font-size:14px;line-height:22px}.monaco-component .multiDiffEntry .header .file-path .status{font-weight:600;line-height:22px;margin:0 10px;opacity:.75}.monaco-component .multiDiffEntry .header .file-path .title.original{flex:1;min-width:0;text-overflow:ellipsis}.monaco-component .multiDiffEntry .header .actions{padding:0 8px}.monaco-component .multiDiffEntry .editorParent{display:flex;flex:1;flex-direction:column}.monaco-component .multiDiffEntry .editorContainer{flex:1}";
1031
- n(css,{});
1032
-
1033
- class ActionRunnerWithContext extends ActionRunner {
1034
- constructor(_getContext) {
1035
- super();
1036
- this._getContext = _getContext;
1037
- }
1038
- runAction(action, _context) {
1039
- return super.runAction(action, this._getContext());
1040
- }
1041
- }
1042
-
1043
- class TemplateData {
1044
- constructor(viewModel) {
1045
- this.viewModel = viewModel;
1046
- }
1047
- getId() {
1048
- return this.viewModel;
1049
- }
1050
- }
1051
- let DiffEditorItemTemplate = class DiffEditorItemTemplate extends Disposable {
1052
- constructor(_container, _overflowWidgetsDomNode, _workbenchUIElementFactory, _instantiationService) {
1053
- super();
1054
- this._container = _container;
1055
- this._overflowWidgetsDomNode = _overflowWidgetsDomNode;
1056
- this._workbenchUIElementFactory = _workbenchUIElementFactory;
1057
- this._instantiationService = _instantiationService;
1058
- this._viewModel = observableValue(this, undefined);
1059
- this._collapsed = derived(this, reader => this._viewModel.read(reader)?.collapsed.read(reader));
1060
- this._editorContentHeight = observableValue(this, 500);
1061
- this.contentHeight = derived(this, reader => {
1062
- const h = this._collapsed.read(reader) ? 0 : this._editorContentHeight.read(reader);
1063
- return h + this._outerEditorHeight;
1064
- });
1065
- this._modifiedContentWidth = observableValue(this, 0);
1066
- this._modifiedWidth = observableValue(this, 0);
1067
- this._originalContentWidth = observableValue(this, 0);
1068
- this._originalWidth = observableValue(this, 0);
1069
- this.maxScroll = derived(this, reader => {
1070
- const scroll1 = this._modifiedContentWidth.read(reader) - this._modifiedWidth.read(reader);
1071
- const scroll2 = this._originalContentWidth.read(reader) - this._originalWidth.read(reader);
1072
- if (scroll1 > scroll2) {
1073
- return { maxScroll: scroll1, width: this._modifiedWidth.read(reader) };
1074
- }
1075
- else {
1076
- return { maxScroll: scroll2, width: this._originalWidth.read(reader) };
1077
- }
1078
- });
1079
- this._elements = h('div.multiDiffEntry', [
1080
- h('div.header@header', [
1081
- h('div.collapse-button@collapseButton'),
1082
- h('div.file-path', [
1083
- h('div.title.modified.show-file-icons@primaryPath', []),
1084
- h('div.status.deleted@status', ['R']),
1085
- h('div.title.original.show-file-icons@secondaryPath', []),
1086
- ]),
1087
- h('div.actions@actions'),
1088
- ]),
1089
- h('div.editorParent', [
1090
- h('div.editorContainer@editor'),
1091
- ])
1092
- ]);
1093
- this.editor = this._register(this._instantiationService.createInstance(DiffEditorWidget, this._elements.editor, {
1094
- overflowWidgetsDomNode: this._overflowWidgetsDomNode,
1095
- }, {}));
1096
- this.isModifedFocused = isFocused(this.editor.getModifiedEditor());
1097
- this.isOriginalFocused = isFocused(this.editor.getOriginalEditor());
1098
- this.isFocused = derived(this, reader => this.isModifedFocused.read(reader) || this.isOriginalFocused.read(reader));
1099
- this._resourceLabel = this._workbenchUIElementFactory.createResourceLabel
1100
- ? this._register(this._workbenchUIElementFactory.createResourceLabel(this._elements.primaryPath))
1101
- : undefined;
1102
- this._resourceLabel2 = this._workbenchUIElementFactory.createResourceLabel
1103
- ? this._register(this._workbenchUIElementFactory.createResourceLabel(this._elements.secondaryPath))
1104
- : undefined;
1105
- this._dataStore = ( new DisposableStore());
1106
- this._headerHeight = 38;
1107
- const btn = ( new Button(this._elements.collapseButton, {}));
1108
- this._register(autorun(reader => {
1109
- btn.element.className = '';
1110
- btn.icon = this._collapsed.read(reader) ? Codicon.chevronRight : Codicon.chevronDown;
1111
- }));
1112
- this._register(btn.onDidClick(() => {
1113
- this._viewModel.get()?.collapsed.set(!this._collapsed.get(), undefined);
1114
- }));
1115
- this._register(autorun(reader => {
1116
- this._elements.editor.style.display = this._collapsed.read(reader) ? 'none' : 'block';
1117
- }));
1118
- this.editor.getModifiedEditor().onDidLayoutChange(e => {
1119
- const width = this.editor.getModifiedEditor().getLayoutInfo().contentWidth;
1120
- this._modifiedWidth.set(width, undefined);
1121
- });
1122
- this.editor.getOriginalEditor().onDidLayoutChange(e => {
1123
- const width = this.editor.getOriginalEditor().getLayoutInfo().contentWidth;
1124
- this._originalWidth.set(width, undefined);
1125
- });
1126
- this._register(this.editor.onDidContentSizeChange(e => {
1127
- globalTransaction(tx => {
1128
- this._editorContentHeight.set(e.contentHeight, tx);
1129
- this._modifiedContentWidth.set(this.editor.getModifiedEditor().getContentWidth(), tx);
1130
- this._originalContentWidth.set(this.editor.getOriginalEditor().getContentWidth(), tx);
1131
- });
1132
- }));
1133
- this._register(autorun(reader => {
1134
- const isFocused = this.isFocused.read(reader);
1135
- this._elements.root.classList.toggle('focused', isFocused);
1136
- }));
1137
- this._container.appendChild(this._elements.root);
1138
- this._outerEditorHeight = 38;
1139
- this._register(this._instantiationService.createInstance(MenuWorkbenchToolBar, this._elements.actions, MenuId.MultiDiffEditorFileToolbar, {
1140
- actionRunner: this._register(( new ActionRunnerWithContext(() => (this._viewModel.get()?.modifiedUri)))),
1141
- menuOptions: {
1142
- shouldForwardArgs: true,
1143
- },
1144
- toolbarOptions: { primaryGroup: g => g.startsWith('navigation') },
1145
- }));
1146
- }
1147
- setScrollLeft(left) {
1148
- if (this._modifiedContentWidth.get() - this._modifiedWidth.get() > this._originalContentWidth.get() - this._originalWidth.get()) {
1149
- this.editor.getModifiedEditor().setScrollLeft(left);
1150
- }
1151
- else {
1152
- this.editor.getOriginalEditor().setScrollLeft(left);
1153
- }
1154
- }
1155
- setData(data) {
1156
- function updateOptions(options) {
1157
- return {
1158
- ...options,
1159
- scrollBeyondLastLine: false,
1160
- hideUnchangedRegions: {
1161
- enabled: true,
1162
- },
1163
- scrollbar: {
1164
- vertical: 'hidden',
1165
- horizontal: 'hidden',
1166
- handleMouseWheel: false,
1167
- useShadows: false,
1168
- },
1169
- renderOverviewRuler: false,
1170
- fixedOverflowWidgets: true,
1171
- overviewRulerBorder: false,
1172
- };
1173
- }
1174
- const value = data.viewModel.entry.value;
1175
- if (value.onOptionsDidChange) {
1176
- this._dataStore.add(value.onOptionsDidChange(() => {
1177
- this.editor.updateOptions(updateOptions(value.options ?? {}));
1178
- }));
1179
- }
1180
- globalTransaction(tx => {
1181
- this._resourceLabel?.setUri(data.viewModel.modifiedUri ?? data.viewModel.originalUri, { strikethrough: data.viewModel.modifiedUri === undefined });
1182
- let isRenamed = false;
1183
- let isDeleted = false;
1184
- let isAdded = false;
1185
- let flag = '';
1186
- if (data.viewModel.modifiedUri && data.viewModel.originalUri && data.viewModel.modifiedUri.path !== data.viewModel.originalUri.path) {
1187
- flag = 'R';
1188
- isRenamed = true;
1189
- }
1190
- else if (!data.viewModel.modifiedUri) {
1191
- flag = 'D';
1192
- isDeleted = true;
1193
- }
1194
- else if (!data.viewModel.originalUri) {
1195
- flag = 'A';
1196
- isAdded = true;
1197
- }
1198
- this._elements.status.classList.toggle('renamed', isRenamed);
1199
- this._elements.status.classList.toggle('deleted', isDeleted);
1200
- this._elements.status.classList.toggle('added', isAdded);
1201
- this._elements.status.innerText = flag;
1202
- this._resourceLabel2?.setUri(isRenamed ? data.viewModel.originalUri : undefined, { strikethrough: true });
1203
- this._dataStore.clear();
1204
- this._viewModel.set(data.viewModel, tx);
1205
- this.editor.setModel(data.viewModel.diffEditorViewModel, tx);
1206
- this.editor.updateOptions(updateOptions(value.options ?? {}));
1207
- });
1208
- }
1209
- render(verticalRange, width, editorScroll, viewPort) {
1210
- this._elements.root.style.visibility = 'visible';
1211
- this._elements.root.style.top = `${verticalRange.start}px`;
1212
- this._elements.root.style.height = `${verticalRange.length}px`;
1213
- this._elements.root.style.width = `${width}px`;
1214
- this._elements.root.style.position = 'absolute';
1215
- const delta = Math.max(0, Math.min(verticalRange.length - this._headerHeight, viewPort.start - verticalRange.start));
1216
- this._elements.header.style.transform = `translateY(${delta}px)`;
1217
- globalTransaction(tx => {
1218
- this.editor.layout({
1219
- width: width,
1220
- height: verticalRange.length - this._outerEditorHeight,
1221
- });
1222
- });
1223
- this.editor.getOriginalEditor().setScrollTop(editorScroll);
1224
- this._elements.header.classList.toggle('shadow', delta > 0 || editorScroll > 0);
1225
- }
1226
- hide() {
1227
- this._elements.root.style.top = `-100000px`;
1228
- this._elements.root.style.visibility = 'hidden';
1229
- }
1230
- };
1231
- DiffEditorItemTemplate = ( __decorate([
1232
- ( __param(3, IInstantiationService))
1233
- ], DiffEditorItemTemplate));
1234
- function isFocused(editor) {
1235
- return observableFromEvent(h => {
1236
- const store = ( new DisposableStore());
1237
- store.add(editor.onDidFocusEditorWidget(() => h(true)));
1238
- store.add(editor.onDidBlurEditorWidget(() => h(false)));
1239
- return store;
1240
- }, () => editor.hasWidgetFocus());
1241
- }
1242
-
1243
- class ObjectPool {
1244
- constructor(_create) {
1245
- this._create = _create;
1246
- this._unused = ( new Set());
1247
- this._used = ( new Set());
1248
- this._itemData = ( new Map());
1249
- }
1250
- getUnusedObj(data) {
1251
- let obj;
1252
- if (this._unused.size === 0) {
1253
- obj = this._create(data);
1254
- this._itemData.set(obj, data);
1255
- }
1256
- else {
1257
- const values = [...( this._unused.values())];
1258
- obj = values.find(obj => this._itemData.get(obj).getId() === data.getId()) ?? values[0];
1259
- this._unused.delete(obj);
1260
- this._itemData.set(obj, data);
1261
- obj.setData(data);
1262
- }
1263
- this._used.add(obj);
1264
- return {
1265
- object: obj,
1266
- dispose: () => {
1267
- this._used.delete(obj);
1268
- if (this._unused.size > 5) {
1269
- obj.dispose();
1270
- }
1271
- else {
1272
- this._unused.add(obj);
1273
- }
1274
- }
1275
- };
1276
- }
1277
- dispose() {
1278
- for (const obj of this._used) {
1279
- obj.dispose();
1280
- }
1281
- for (const obj of this._unused) {
1282
- obj.dispose();
1283
- }
1284
- this._used.clear();
1285
- this._unused.clear();
1286
- }
1287
- }
1288
-
1289
- let MultiDiffEditorWidgetImpl = class MultiDiffEditorWidgetImpl extends Disposable {
1290
- constructor(_element, _dimension, _viewModel, _workbenchUIElementFactory, _parentContextKeyService, _parentInstantiationService) {
1291
- super();
1292
- this._element = _element;
1293
- this._dimension = _dimension;
1294
- this._viewModel = _viewModel;
1295
- this._workbenchUIElementFactory = _workbenchUIElementFactory;
1296
- this._parentContextKeyService = _parentContextKeyService;
1297
- this._parentInstantiationService = _parentInstantiationService;
1298
- this._elements = h('div.monaco-component.multiDiffEditor', [
1299
- h('div@content', {
1300
- style: {
1301
- overflow: 'hidden',
1302
- }
1303
- }),
1304
- h('div.monaco-editor@overflowWidgetsDomNode', {}),
1305
- ]);
1306
- this._sizeObserver = this._register(( new ObservableElementSizeObserver(this._element, undefined)));
1307
- this._objectPool = this._register(( new ObjectPool((data) => {
1308
- const template = this._instantiationService.createInstance(DiffEditorItemTemplate, this._elements.content, this._elements.overflowWidgetsDomNode, this._workbenchUIElementFactory);
1309
- template.setData(data);
1310
- return template;
1311
- })));
1312
- this._scrollable = this._register(( new Scrollable({
1313
- forceIntegerValues: false,
1314
- scheduleAtNextAnimationFrame: (cb) => scheduleAtNextAnimationFrame(getWindow(this._element), cb),
1315
- smoothScrollDuration: 100,
1316
- })));
1317
- this._scrollableElement = this._register(( new SmoothScrollableElement(this._elements.root, {
1318
- vertical: 1 ,
1319
- horizontal: 1 ,
1320
- useShadows: false,
1321
- }, this._scrollable)));
1322
- this.scrollTop = observableFromEvent(this._scrollableElement.onScroll, () => this._scrollableElement.getScrollPosition().scrollTop);
1323
- this.scrollLeft = observableFromEvent(this._scrollableElement.onScroll, () => this._scrollableElement.getScrollPosition().scrollLeft);
1324
- this._viewItems = derivedWithStore(this, (reader, store) => {
1325
- const vm = this._viewModel.read(reader);
1326
- if (!vm) {
1327
- return [];
1328
- }
1329
- const items = vm.items.read(reader);
1330
- return ( items.map(d => {
1331
- const item = store.add(( new VirtualizedViewItem(d, this._objectPool, this.scrollLeft)));
1332
- const data = this._lastDocStates?.[item.getKey()];
1333
- if (data) {
1334
- transaction(tx => {
1335
- item.setViewState(data, tx);
1336
- });
1337
- }
1338
- return item;
1339
- }));
1340
- });
1341
- this._spaceBetweenPx = 10;
1342
- this._totalHeight = ( this._viewItems.map(
1343
- this,
1344
- (items, reader) => items.reduce((r, i) => r + i.contentHeight.read(reader) + this._spaceBetweenPx, 0)
1345
- ));
1346
- this.activeDiffItem = derived(this, reader => this._viewItems.read(reader).find(i => i.template.read(reader)?.isFocused.read(reader)));
1347
- this.lastActiveDiffItem = derivedObservableWithCache((reader, lastValue) => this.activeDiffItem.read(reader) ?? lastValue);
1348
- this.activeControl = derived(this, reader => this.lastActiveDiffItem.read(reader)?.template.read(reader)?.editor);
1349
- this._contextKeyService = this._register(this._parentContextKeyService.createScoped(this._element));
1350
- this._instantiationService = this._parentInstantiationService.createChild(( new ServiceCollection([IContextKeyService, this._contextKeyService])));
1351
- this._lastDocStates = {};
1352
- this._contextKeyService.createKey(EditorContextKeys.inMultiDiffEditor.key, true);
1353
- this._register(autorunWithStore((reader, store) => {
1354
- const viewModel = this._viewModel.read(reader);
1355
- if (viewModel && viewModel.contextKeys) {
1356
- for (const [key, value] of Object.entries(viewModel.contextKeys)) {
1357
- const contextKey = this._contextKeyService.createKey(key, undefined);
1358
- contextKey.set(value);
1359
- store.add(toDisposable(() => contextKey.reset()));
1360
- }
1361
- }
1362
- }));
1363
- const ctxAllCollapsed = this._parentContextKeyService.createKey(EditorContextKeys.multiDiffEditorAllCollapsed.key, false);
1364
- this._register(autorun((reader) => {
1365
- const viewModel = this._viewModel.read(reader);
1366
- if (viewModel) {
1367
- const allCollapsed = viewModel.items.read(reader).every(item => item.collapsed.read(reader));
1368
- ctxAllCollapsed.set(allCollapsed);
1369
- }
1370
- }));
1371
- this._register(autorun((reader) => {
1372
- const lastActiveDiffItem = this.lastActiveDiffItem.read(reader);
1373
- transaction(tx => {
1374
- this._viewModel.read(reader)?.activeDiffItem.set(lastActiveDiffItem?.viewModel, tx);
1375
- });
1376
- }));
1377
- this._register(autorun((reader) => {
1378
- const dimension = this._dimension.read(reader);
1379
- this._sizeObserver.observe(dimension);
1380
- }));
1381
- this._elements.content.style.position = 'relative';
1382
- this._register(autorun((reader) => {
1383
- const height = this._sizeObserver.height.read(reader);
1384
- this._elements.root.style.height = `${height}px`;
1385
- const totalHeight = this._totalHeight.read(reader);
1386
- this._elements.content.style.height = `${totalHeight}px`;
1387
- const width = this._sizeObserver.width.read(reader);
1388
- let scrollWidth = width;
1389
- const viewItems = this._viewItems.read(reader);
1390
- const max = findFirstMaxBy(viewItems, i => i.maxScroll.read(reader).maxScroll);
1391
- if (max) {
1392
- const maxScroll = max.maxScroll.read(reader);
1393
- scrollWidth = width + maxScroll.maxScroll;
1394
- }
1395
- this._scrollableElement.setScrollDimensions({
1396
- width: width,
1397
- height: height,
1398
- scrollHeight: totalHeight,
1399
- scrollWidth,
1400
- });
1401
- }));
1402
- _element.replaceChildren(this._scrollableElement.getDomNode());
1403
- this._register(toDisposable(() => {
1404
- _element.replaceChildren();
1405
- }));
1406
- this._register(this._register(autorun(reader => {
1407
- globalTransaction(tx => {
1408
- this.render(reader);
1409
- });
1410
- })));
1411
- }
1412
- setScrollState(scrollState) {
1413
- this._scrollableElement.setScrollPosition({ scrollLeft: scrollState.left, scrollTop: scrollState.top });
1414
- }
1415
- getViewState() {
1416
- return {
1417
- scrollState: {
1418
- top: this.scrollTop.get(),
1419
- left: this.scrollLeft.get(),
1420
- },
1421
- docStates: Object.fromEntries(( this._viewItems.get().map(i => [i.getKey(), i.getViewState()]))),
1422
- };
1423
- }
1424
- setViewState(viewState) {
1425
- this.setScrollState(viewState.scrollState);
1426
- this._lastDocStates = viewState.docStates;
1427
- transaction(tx => {
1428
- if (viewState.docStates) {
1429
- for (const i of this._viewItems.get()) {
1430
- const state = viewState.docStates[i.getKey()];
1431
- if (state) {
1432
- i.setViewState(state, tx);
1433
- }
1434
- }
1435
- }
1436
- });
1437
- }
1438
- tryGetCodeEditor(resource) {
1439
- const item = this._viewItems.get().find(v => ( v.viewModel.diffEditorViewModel.model.modified.uri.toString()) === ( resource.toString())
1440
- || ( v.viewModel.diffEditorViewModel.model.original.uri.toString()) === ( resource.toString()));
1441
- const editor = item?.template.get()?.editor;
1442
- if (!editor) {
1443
- return undefined;
1444
- }
1445
- if (( item.viewModel.diffEditorViewModel.model.modified.uri.toString()) === ( resource.toString())) {
1446
- return { diffEditor: editor, editor: editor.getModifiedEditor() };
1447
- }
1448
- else {
1449
- return { diffEditor: editor, editor: editor.getOriginalEditor() };
1450
- }
1451
- }
1452
- render(reader) {
1453
- const scrollTop = this.scrollTop.read(reader);
1454
- let contentScrollOffsetToScrollOffset = 0;
1455
- let itemHeightSumBefore = 0;
1456
- let itemContentHeightSumBefore = 0;
1457
- const viewPortHeight = this._sizeObserver.height.read(reader);
1458
- const contentViewPort = OffsetRange.ofStartAndLength(scrollTop, viewPortHeight);
1459
- const width = this._sizeObserver.width.read(reader);
1460
- for (const v of this._viewItems.read(reader)) {
1461
- const itemContentHeight = v.contentHeight.read(reader);
1462
- const itemHeight = Math.min(itemContentHeight, viewPortHeight);
1463
- const itemRange = OffsetRange.ofStartAndLength(itemHeightSumBefore, itemHeight);
1464
- const itemContentRange = OffsetRange.ofStartAndLength(itemContentHeightSumBefore, itemContentHeight);
1465
- if (itemContentRange.isBefore(contentViewPort)) {
1466
- contentScrollOffsetToScrollOffset -= itemContentHeight - itemHeight;
1467
- v.hide();
1468
- }
1469
- else if (itemContentRange.isAfter(contentViewPort)) {
1470
- v.hide();
1471
- }
1472
- else {
1473
- const scroll = Math.max(0, Math.min(contentViewPort.start - itemContentRange.start, itemContentHeight - itemHeight));
1474
- contentScrollOffsetToScrollOffset -= scroll;
1475
- const viewPort = OffsetRange.ofStartAndLength(scrollTop + contentScrollOffsetToScrollOffset, viewPortHeight);
1476
- v.render(itemRange, scroll, width, viewPort);
1477
- }
1478
- itemHeightSumBefore += itemHeight + this._spaceBetweenPx;
1479
- itemContentHeightSumBefore += itemContentHeight + this._spaceBetweenPx;
1480
- }
1481
- this._elements.content.style.transform = `translateY(${-(scrollTop + contentScrollOffsetToScrollOffset)}px)`;
1482
- }
1483
- };
1484
- MultiDiffEditorWidgetImpl = ( __decorate([
1485
- ( __param(4, IContextKeyService)),
1486
- ( __param(5, IInstantiationService))
1487
- ], MultiDiffEditorWidgetImpl));
1488
- class VirtualizedViewItem extends Disposable {
1489
- constructor(viewModel, _objectPool, _scrollLeft) {
1490
- super();
1491
- this.viewModel = viewModel;
1492
- this._objectPool = _objectPool;
1493
- this._scrollLeft = _scrollLeft;
1494
- this._templateRef = this._register(disposableObservableValue(this, undefined));
1495
- this.contentHeight = derived(this, reader => this._templateRef.read(reader)?.object.contentHeight?.read(reader) ?? this.viewModel.lastTemplateData.read(reader).contentHeight);
1496
- this.maxScroll = derived(this, reader => this._templateRef.read(reader)?.object.maxScroll.read(reader) ?? { maxScroll: 0, scrollWidth: 0 });
1497
- this.template = derived(this, reader => this._templateRef.read(reader)?.object);
1498
- this._isHidden = observableValue(this, false);
1499
- this._register(autorun((reader) => {
1500
- const scrollLeft = this._scrollLeft.read(reader);
1501
- this._templateRef.read(reader)?.object.setScrollLeft(scrollLeft);
1502
- }));
1503
- this._register(autorun(reader => {
1504
- const ref = this._templateRef.read(reader);
1505
- if (!ref) {
1506
- return;
1507
- }
1508
- const isHidden = this._isHidden.read(reader);
1509
- if (!isHidden) {
1510
- return;
1511
- }
1512
- const isFocused = ref.object.isFocused.read(reader);
1513
- if (isFocused) {
1514
- return;
1515
- }
1516
- this._clear();
1517
- }));
1518
- }
1519
- dispose() {
1520
- this._clear();
1521
- super.dispose();
1522
- }
1523
- toString() {
1524
- return `VirtualViewItem(${this.viewModel.entry.value.modified?.uri.toString()})`;
1525
- }
1526
- getKey() {
1527
- return this.viewModel.getKey();
1528
- }
1529
- getViewState() {
1530
- transaction(tx => {
1531
- this._updateTemplateData(tx);
1532
- });
1533
- return {
1534
- collapsed: this.viewModel.collapsed.get(),
1535
- selections: this.viewModel.lastTemplateData.get().selections,
1536
- };
1537
- }
1538
- setViewState(viewState, tx) {
1539
- this.viewModel.collapsed.set(viewState.collapsed, tx);
1540
- this._updateTemplateData(tx);
1541
- const data = this.viewModel.lastTemplateData.get();
1542
- const selections = viewState.selections?.map(Selection$1.liftSelection);
1543
- this.viewModel.lastTemplateData.set({
1544
- ...data,
1545
- selections,
1546
- }, tx);
1547
- const ref = this._templateRef.get();
1548
- if (ref) {
1549
- if (selections) {
1550
- ref.object.editor.setSelections(selections);
1551
- }
1552
- }
1553
- }
1554
- _updateTemplateData(tx) {
1555
- const ref = this._templateRef.get();
1556
- if (!ref) {
1557
- return;
1558
- }
1559
- this.viewModel.lastTemplateData.set({
1560
- contentHeight: ref.object.contentHeight.get(),
1561
- selections: ref.object.editor.getSelections() ?? undefined,
1562
- }, tx);
1563
- }
1564
- _clear() {
1565
- const ref = this._templateRef.get();
1566
- if (!ref) {
1567
- return;
1568
- }
1569
- transaction(tx => {
1570
- this._updateTemplateData(tx);
1571
- ref.object.hide();
1572
- this._templateRef.set(undefined, tx);
1573
- });
1574
- }
1575
- hide() {
1576
- this._isHidden.set(true, undefined);
1577
- }
1578
- render(verticalSpace, offset, width, viewPort) {
1579
- this._isHidden.set(false, undefined);
1580
- let ref = this._templateRef.get();
1581
- if (!ref) {
1582
- ref = this._objectPool.getUnusedObj(( new TemplateData(this.viewModel)));
1583
- this._templateRef.set(ref, undefined);
1584
- const selections = this.viewModel.lastTemplateData.get().selections;
1585
- if (selections) {
1586
- ref.object.editor.setSelections(selections);
1587
- }
1588
- }
1589
- ref.object.render(verticalSpace, width, offset, viewPort);
1590
- }
1591
- }
1592
-
1593
- class MultiDiffEditorViewModel extends Disposable {
1594
- async waitForDiffs() {
1595
- for (const d of this.items.get()) {
1596
- await d.diffEditorViewModel.waitForDiff();
1597
- }
1598
- }
1599
- collapseAll() {
1600
- transaction(tx => {
1601
- for (const d of this.items.get()) {
1602
- d.collapsed.set(true, tx);
1603
- }
1604
- });
1605
- }
1606
- expandAll() {
1607
- transaction(tx => {
1608
- for (const d of this.items.get()) {
1609
- d.collapsed.set(false, tx);
1610
- }
1611
- });
1612
- }
1613
- get contextKeys() {
1614
- return this.model.contextKeys;
1615
- }
1616
- constructor(model, _instantiationService) {
1617
- super();
1618
- this.model = model;
1619
- this._instantiationService = _instantiationService;
1620
- this._documents = observableFromEvent(this.model.onDidChange, () => this.model.documents);
1621
- this.items = mapObservableArrayCached(this, this._documents, (d, store) => store.add(this._instantiationService.createInstance(DocumentDiffItemViewModel, d)))
1622
- .recomputeInitiallyAndOnChange(this._store);
1623
- this.activeDiffItem = observableValue(this, undefined);
1624
- }
1625
- }
1626
- let DocumentDiffItemViewModel = class DocumentDiffItemViewModel extends Disposable {
1627
- get originalUri() { return this.entry.value.original?.uri; }
1628
- get modifiedUri() { return this.entry.value.modified?.uri; }
1629
- constructor(entry, _instantiationService, _modelService) {
1630
- super();
1631
- this.entry = entry;
1632
- this._instantiationService = _instantiationService;
1633
- this._modelService = _modelService;
1634
- this.collapsed = observableValue(this, false);
1635
- this.lastTemplateData = observableValue(this, { contentHeight: 500, selections: undefined, });
1636
- function updateOptions(options) {
1637
- return {
1638
- ...options,
1639
- hideUnchangedRegions: {
1640
- enabled: true,
1641
- },
1642
- };
1643
- }
1644
- const options = ( new DiffEditorOptions(updateOptions(this.entry.value.options || {})));
1645
- if (this.entry.value.onOptionsDidChange) {
1646
- this._register(this.entry.value.onOptionsDidChange(() => {
1647
- options.updateOptions(updateOptions(this.entry.value.options || {}));
1648
- }));
1649
- }
1650
- const originalTextModel = this.entry.value.original ?? this._register(this._modelService.createModel('', null));
1651
- const modifiedTextModel = this.entry.value.modified ?? this._register(this._modelService.createModel('', null));
1652
- this.diffEditorViewModel = this._register(this._instantiationService.createInstance(DiffEditorViewModel, {
1653
- original: originalTextModel,
1654
- modified: modifiedTextModel,
1655
- }, options));
1656
- }
1657
- getKey() {
1658
- return JSON.stringify([
1659
- this.originalUri?.toString(),
1660
- this.modifiedUri?.toString()
1661
- ]);
1662
- }
1663
- };
1664
- DocumentDiffItemViewModel = ( __decorate([
1665
- ( __param(1, IInstantiationService)),
1666
- ( __param(2, IModelService))
1667
- ], DocumentDiffItemViewModel));
1668
-
1669
- registerColor('multiDiffEditor.headerBackground', { dark: '#808080', light: '#b4b4b4', hcDark: '#808080', hcLight: '#b4b4b4', }, ( localizeWithPath(
1670
- 'vs/editor/browser/widget/multiDiffEditorWidget/colors',
1671
- 'multiDiffEditor.headerBackground',
1672
- 'The background color of the diff editor\'s header'
1673
- )));
1674
- registerColor('multiDiffEditor.background', { dark: '#000000', light: '#e5e5e5', hcDark: '#000000', hcLight: '#e5e5e5', }, ( localizeWithPath(
1675
- 'vs/editor/browser/widget/multiDiffEditorWidget/colors',
1676
- 'multiDiffEditor.background',
1677
- 'The background color of the multi file diff editor'
1678
- )));
1679
- registerColor('multiDiffEditor.border', { dark: 'sideBarSectionHeader.border', light: '#cccccc', hcDark: 'sideBarSectionHeader.border', hcLight: '#cccccc', }, ( localizeWithPath(
1680
- 'vs/editor/browser/widget/multiDiffEditorWidget/colors',
1681
- 'multiDiffEditor.border',
1682
- 'The border color of the multi file diff editor'
1683
- )));
1684
-
1685
- let MultiDiffEditorWidget = class MultiDiffEditorWidget extends Disposable {
1686
- constructor(_element, _workbenchUIElementFactory, _instantiationService) {
1687
- super();
1688
- this._element = _element;
1689
- this._workbenchUIElementFactory = _workbenchUIElementFactory;
1690
- this._instantiationService = _instantiationService;
1691
- this._dimension = observableValue(this, undefined);
1692
- this._viewModel = observableValue(this, undefined);
1693
- this._widgetImpl = derivedWithStore(this, (reader, store) => {
1694
- readHotReloadableExport(DiffEditorItemTemplate, reader);
1695
- return store.add(this._instantiationService.createInstance((readHotReloadableExport(MultiDiffEditorWidgetImpl, reader)), this._element, this._dimension, this._viewModel, this._workbenchUIElementFactory));
1696
- });
1697
- this._activeControl = derived(this, (reader) => this._widgetImpl.read(reader).activeControl.read(reader));
1698
- this.onDidChangeActiveControl = Event.fromObservableLight(this._activeControl);
1699
- this._register(recomputeInitiallyAndOnChange(this._widgetImpl));
1700
- }
1701
- createViewModel(model) {
1702
- return ( new MultiDiffEditorViewModel(model, this._instantiationService));
1703
- }
1704
- setViewModel(viewModel) {
1705
- this._viewModel.set(viewModel, undefined);
1706
- }
1707
- layout(dimension) {
1708
- this._dimension.set(dimension, undefined);
1709
- }
1710
- getActiveControl() {
1711
- return this._activeControl.get();
1712
- }
1713
- getViewState() {
1714
- return this._widgetImpl.get().getViewState();
1715
- }
1716
- setViewState(viewState) {
1717
- this._widgetImpl.get().setViewState(viewState);
1718
- }
1719
- tryGetCodeEditor(resource) {
1720
- return this._widgetImpl.get().tryGetCodeEditor(resource);
1721
- }
1722
- };
1723
- MultiDiffEditorWidget = ( __decorate([
1724
- ( __param(2, IInstantiationService))
1725
- ], MultiDiffEditorWidget));
1726
-
1727
1005
  function create(domElement, options, override) {
1728
1006
  const instantiationService = StandaloneServices.initialize(override || {});
1729
1007
  return instantiationService.createInstance(StandaloneEditor, domElement, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-editor-api",
3
- "version": "2.1.4",
3
+ "version": "2.2.0-next.1",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,6 +18,6 @@
18
18
  "module": "esm/vs/editor/editor.api.js",
19
19
  "types": "esm/vs/editor/editor.api.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@2.1.4"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@2.2.0-next.1"
22
22
  }
23
23
  }