@codingame/monaco-vscode-a17e9d37-b6c1-5556-8402-5db73960fae3-common 20.0.0

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.
@@ -0,0 +1,254 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
4
+ import { deepClone, distinct } from '@codingame/monaco-vscode-api/vscode/vs/base/common/objects';
5
+ import { Emitter, Event } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
6
+ import { isObject, assertReturnsDefined } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
7
+ import { MutableDisposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
8
+ import { EditorPaneSelectionChangeReason, EditorPaneSelectionCompareResult } from '@codingame/monaco-vscode-api/vscode/vs/workbench/common/editor';
9
+ import { computeEditorAriaLabel } from '@codingame/monaco-vscode-60014c9d-b815-501d-83a9-4b08725c2ec2-common/vscode/vs/workbench/browser/editor';
10
+ import { AbstractEditorWithViewState } from './editorWithViewState.js';
11
+ import { IStorageService } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service';
12
+ import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
13
+ import { ITelemetryService } from '@codingame/monaco-vscode-api/vscode/vs/platform/telemetry/common/telemetry.service';
14
+ import { IThemeService } from '@codingame/monaco-vscode-api/vscode/vs/platform/theme/common/themeService.service';
15
+ import { ITextResourceConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/textResourceConfiguration.service';
16
+ import { IEditorGroupsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService.service';
17
+ import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
18
+ import { TextEditorSelectionSource, TextEditorSelectionRevealType } from '@codingame/monaco-vscode-api/vscode/vs/platform/editor/common/editor';
19
+ import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
20
+
21
+ var AbstractTextEditor_1;
22
+ let AbstractTextEditor = class AbstractTextEditor extends AbstractEditorWithViewState {
23
+ static { AbstractTextEditor_1 = this; }
24
+ static { this.VIEW_STATE_PREFERENCE_KEY = 'textEditorViewState'; }
25
+ constructor(id, group, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorService, editorGroupService, fileService) {
26
+ super(id, group, AbstractTextEditor_1.VIEW_STATE_PREFERENCE_KEY, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorService, editorGroupService);
27
+ this.fileService = fileService;
28
+ this._onDidChangeSelection = this._register(( new Emitter()));
29
+ this.onDidChangeSelection = this._onDidChangeSelection.event;
30
+ this._onDidChangeScroll = this._register(( new Emitter()));
31
+ this.onDidChangeScroll = this._onDidChangeScroll.event;
32
+ this.inputListener = this._register(( new MutableDisposable()));
33
+ this._register(this.textResourceConfigurationService.onDidChangeConfiguration(e => this.handleConfigurationChangeEvent(e)));
34
+ this._register(Event.any(this.editorGroupService.onDidAddGroup, this.editorGroupService.onDidRemoveGroup)(() => {
35
+ const ariaLabel = this.computeAriaLabel();
36
+ this.editorContainer?.setAttribute('aria-label', ariaLabel);
37
+ this.updateEditorControlOptions({ ariaLabel });
38
+ }));
39
+ this._register(this.fileService.onDidChangeFileSystemProviderCapabilities(e => this.onDidChangeFileSystemProvider(e.scheme)));
40
+ this._register(this.fileService.onDidChangeFileSystemProviderRegistrations(e => this.onDidChangeFileSystemProvider(e.scheme)));
41
+ }
42
+ handleConfigurationChangeEvent(e) {
43
+ const resource = this.getActiveResource();
44
+ if (!this.shouldHandleConfigurationChangeEvent(e, resource)) {
45
+ return;
46
+ }
47
+ if (this.isVisible()) {
48
+ this.updateEditorConfiguration(resource);
49
+ }
50
+ else {
51
+ this.hasPendingConfigurationChange = true;
52
+ }
53
+ }
54
+ shouldHandleConfigurationChangeEvent(e, resource) {
55
+ return e.affectsConfiguration(resource, 'editor') || e.affectsConfiguration(resource, 'problems.visibility');
56
+ }
57
+ consumePendingConfigurationChangeEvent() {
58
+ if (this.hasPendingConfigurationChange) {
59
+ this.updateEditorConfiguration();
60
+ this.hasPendingConfigurationChange = false;
61
+ }
62
+ }
63
+ computeConfiguration(configuration) {
64
+ const editorConfiguration = isObject(configuration.editor) ? deepClone(configuration.editor) : Object.create(null);
65
+ Object.assign(editorConfiguration, this.getConfigurationOverrides(configuration));
66
+ editorConfiguration.ariaLabel = this.computeAriaLabel();
67
+ return editorConfiguration;
68
+ }
69
+ computeAriaLabel() {
70
+ return this.input ? computeEditorAriaLabel(this.input, undefined, this.group, this.editorGroupService.count) : ( localize(3412, "Editor"));
71
+ }
72
+ onDidChangeFileSystemProvider(scheme) {
73
+ if (!this.input) {
74
+ return;
75
+ }
76
+ if (this.getActiveResource()?.scheme === scheme) {
77
+ this.updateReadonly(this.input);
78
+ }
79
+ }
80
+ onDidChangeInputCapabilities(input) {
81
+ if (this.input === input) {
82
+ this.updateReadonly(input);
83
+ }
84
+ }
85
+ updateReadonly(input) {
86
+ this.updateEditorControlOptions({ ...this.getReadonlyConfiguration(input.isReadonly()) });
87
+ }
88
+ getReadonlyConfiguration(isReadonly) {
89
+ return {
90
+ readOnly: !!isReadonly,
91
+ readOnlyMessage: typeof isReadonly !== 'boolean' ? isReadonly : undefined
92
+ };
93
+ }
94
+ getConfigurationOverrides(configuration) {
95
+ return {
96
+ overviewRulerLanes: 3,
97
+ lineNumbersMinChars: 3,
98
+ fixedOverflowWidgets: true,
99
+ ...this.getReadonlyConfiguration(this.input?.isReadonly()),
100
+ renderValidationDecorations: configuration.problems?.visibility !== false ? 'on' : 'off'
101
+ };
102
+ }
103
+ createEditor(parent) {
104
+ this.editorContainer = parent;
105
+ this.createEditorControl(parent, this.computeConfiguration(this.textResourceConfigurationService.getValue(this.getActiveResource())));
106
+ this.registerCodeEditorListeners();
107
+ }
108
+ registerCodeEditorListeners() {
109
+ const mainControl = this.getMainControl();
110
+ if (mainControl) {
111
+ this._register(mainControl.onDidChangeModelLanguage(() => this.updateEditorConfiguration()));
112
+ this._register(mainControl.onDidChangeModel(() => this.updateEditorConfiguration()));
113
+ this._register(mainControl.onDidChangeCursorPosition(e => this._onDidChangeSelection.fire({ reason: this.toEditorPaneSelectionChangeReason(e) })));
114
+ this._register(mainControl.onDidChangeModelContent(() => this._onDidChangeSelection.fire({ reason: EditorPaneSelectionChangeReason.EDIT })));
115
+ this._register(mainControl.onDidScrollChange(() => this._onDidChangeScroll.fire()));
116
+ }
117
+ }
118
+ toEditorPaneSelectionChangeReason(e) {
119
+ switch (e.source) {
120
+ case TextEditorSelectionSource.PROGRAMMATIC: return EditorPaneSelectionChangeReason.PROGRAMMATIC;
121
+ case TextEditorSelectionSource.NAVIGATION: return EditorPaneSelectionChangeReason.NAVIGATION;
122
+ case TextEditorSelectionSource.JUMP: return EditorPaneSelectionChangeReason.JUMP;
123
+ default: return EditorPaneSelectionChangeReason.USER;
124
+ }
125
+ }
126
+ getSelection() {
127
+ const mainControl = this.getMainControl();
128
+ if (mainControl) {
129
+ const selection = mainControl.getSelection();
130
+ if (selection) {
131
+ return ( new TextEditorPaneSelection(selection));
132
+ }
133
+ }
134
+ return undefined;
135
+ }
136
+ async setInput(input, options, context, token) {
137
+ await super.setInput(input, options, context, token);
138
+ this.inputListener.value = input.onDidChangeCapabilities(() => this.onDidChangeInputCapabilities(input));
139
+ this.updateEditorConfiguration();
140
+ const editorContainer = assertReturnsDefined(this.editorContainer);
141
+ editorContainer.setAttribute('aria-label', this.computeAriaLabel());
142
+ }
143
+ clearInput() {
144
+ this.inputListener.clear();
145
+ super.clearInput();
146
+ }
147
+ getScrollPosition() {
148
+ const editor = this.getMainControl();
149
+ if (!editor) {
150
+ throw ( new Error('Control has not yet been initialized'));
151
+ }
152
+ return {
153
+ scrollTop: editor.getScrollTop() - editor.getTopForLineNumber(1),
154
+ scrollLeft: editor.getScrollLeft(),
155
+ };
156
+ }
157
+ setScrollPosition(scrollPosition) {
158
+ const editor = this.getMainControl();
159
+ if (!editor) {
160
+ throw ( new Error('Control has not yet been initialized'));
161
+ }
162
+ editor.setScrollTop(scrollPosition.scrollTop);
163
+ if (scrollPosition.scrollLeft) {
164
+ editor.setScrollLeft(scrollPosition.scrollLeft);
165
+ }
166
+ }
167
+ setEditorVisible(visible) {
168
+ if (visible) {
169
+ this.consumePendingConfigurationChangeEvent();
170
+ }
171
+ super.setEditorVisible(visible);
172
+ }
173
+ toEditorViewStateResource(input) {
174
+ return input.resource;
175
+ }
176
+ updateEditorConfiguration(resource = this.getActiveResource()) {
177
+ let configuration = undefined;
178
+ if (resource) {
179
+ configuration = this.textResourceConfigurationService.getValue(resource);
180
+ }
181
+ if (!configuration) {
182
+ return;
183
+ }
184
+ const editorConfiguration = this.computeConfiguration(configuration);
185
+ let editorSettingsToApply = editorConfiguration;
186
+ if (this.lastAppliedEditorOptions) {
187
+ editorSettingsToApply = distinct(this.lastAppliedEditorOptions, editorSettingsToApply);
188
+ }
189
+ if (( Object.keys(editorSettingsToApply)).length > 0) {
190
+ this.lastAppliedEditorOptions = editorConfiguration;
191
+ this.updateEditorControlOptions(editorSettingsToApply);
192
+ }
193
+ }
194
+ getActiveResource() {
195
+ const mainControl = this.getMainControl();
196
+ if (mainControl) {
197
+ const model = mainControl.getModel();
198
+ if (model) {
199
+ return model.uri;
200
+ }
201
+ }
202
+ if (this.input) {
203
+ return this.input.resource;
204
+ }
205
+ return undefined;
206
+ }
207
+ dispose() {
208
+ this.lastAppliedEditorOptions = undefined;
209
+ super.dispose();
210
+ }
211
+ };
212
+ AbstractTextEditor = AbstractTextEditor_1 = ( __decorate([
213
+ ( __param(2, ITelemetryService)),
214
+ ( __param(3, IInstantiationService)),
215
+ ( __param(4, IStorageService)),
216
+ ( __param(5, ITextResourceConfigurationService)),
217
+ ( __param(6, IThemeService)),
218
+ ( __param(7, IEditorService)),
219
+ ( __param(8, IEditorGroupsService)),
220
+ ( __param(9, IFileService))
221
+ ], AbstractTextEditor));
222
+ class TextEditorPaneSelection {
223
+ static { this.TEXT_EDITOR_SELECTION_THRESHOLD = 10; }
224
+ constructor(textSelection) {
225
+ this.textSelection = textSelection;
226
+ }
227
+ compare(other) {
228
+ if (!(other instanceof TextEditorPaneSelection)) {
229
+ return EditorPaneSelectionCompareResult.DIFFERENT;
230
+ }
231
+ const thisLineNumber = Math.min(this.textSelection.selectionStartLineNumber, this.textSelection.positionLineNumber);
232
+ const otherLineNumber = Math.min(other.textSelection.selectionStartLineNumber, other.textSelection.positionLineNumber);
233
+ if (thisLineNumber === otherLineNumber) {
234
+ return EditorPaneSelectionCompareResult.IDENTICAL;
235
+ }
236
+ if (Math.abs(thisLineNumber - otherLineNumber) < TextEditorPaneSelection.TEXT_EDITOR_SELECTION_THRESHOLD) {
237
+ return EditorPaneSelectionCompareResult.SIMILAR;
238
+ }
239
+ return EditorPaneSelectionCompareResult.DIFFERENT;
240
+ }
241
+ restore(options) {
242
+ const textEditorOptions = {
243
+ ...options,
244
+ selection: this.textSelection,
245
+ selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport
246
+ };
247
+ return textEditorOptions;
248
+ }
249
+ log() {
250
+ return `line: ${this.textSelection.startLineNumber}-${this.textSelection.endLineNumber}, col: ${this.textSelection.startColumn}-${this.textSelection.endColumn}`;
251
+ }
252
+ }
253
+
254
+ export { AbstractTextEditor, TextEditorPaneSelection };
@@ -0,0 +1,8 @@
1
+ import { IConfigurationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service";
2
+ import { GroupIdentifier } from "@codingame/monaco-vscode-api/vscode/vs/workbench/common/editor";
3
+ import { IEditorGroup } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService";
4
+ import { IEditorGroupsService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService.service";
5
+ import { ACTIVE_GROUP_TYPE, SIDE_GROUP_TYPE } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService";
6
+ export type EditorGroupColumn = number;
7
+ export declare function columnToEditorGroup(editorGroupService: IEditorGroupsService, configurationService: IConfigurationService, column?: number): GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE;
8
+ export declare function editorGroupToColumn(editorGroupService: IEditorGroupsService, editorGroup: IEditorGroup | GroupIdentifier): EditorGroupColumn;
@@ -0,0 +1,26 @@
1
+
2
+ import { GroupsOrder, preferredSideBySideGroupDirection } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService';
3
+ import { ACTIVE_GROUP, SIDE_GROUP } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService';
4
+
5
+ function columnToEditorGroup(editorGroupService, configurationService, column = ACTIVE_GROUP) {
6
+ if (column === ACTIVE_GROUP || column === SIDE_GROUP) {
7
+ return column;
8
+ }
9
+ let groupInColumn = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE)[column];
10
+ if (!groupInColumn && column < 9) {
11
+ for (let i = 0; i <= column; i++) {
12
+ const editorGroups = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE);
13
+ if (!editorGroups[i]) {
14
+ editorGroupService.addGroup(editorGroups[i - 1], preferredSideBySideGroupDirection(configurationService));
15
+ }
16
+ }
17
+ groupInColumn = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE)[column];
18
+ }
19
+ return groupInColumn?.id ?? SIDE_GROUP;
20
+ }
21
+ function editorGroupToColumn(editorGroupService, editorGroup) {
22
+ const group = (typeof editorGroup === 'number') ? editorGroupService.getGroup(editorGroup) : editorGroup;
23
+ return editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE).indexOf(group ?? editorGroupService.activeGroup);
24
+ }
25
+
26
+ export { columnToEditorGroup, editorGroupToColumn };