Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/standalone/browser/standaloneCodeEditor.ts
5221 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as aria from '../../../base/browser/ui/aria/aria.js';
7
import { Disposable, IDisposable, toDisposable, DisposableStore } from '../../../base/common/lifecycle.js';
8
import { ICodeEditor, IDiffEditor, IDiffEditorConstructionOptions } from '../../browser/editorBrowser.js';
9
import { ICodeEditorService } from '../../browser/services/codeEditorService.js';
10
import { CodeEditorWidget } from '../../browser/widget/codeEditor/codeEditorWidget.js';
11
import { IDiffEditorOptions, IEditorOptions } from '../../common/config/editorOptions.js';
12
import { InternalEditorAction } from '../../common/editorAction.js';
13
import { IModelChangedEvent } from '../../common/editorCommon.js';
14
import { ITextModel } from '../../common/model.js';
15
import { StandaloneKeybindingService, updateConfigurationService } from './standaloneServices.js';
16
import { IStandaloneThemeService } from '../common/standaloneTheme.js';
17
import { IMenuItem, MenuId, MenuRegistry } from '../../../platform/actions/common/actions.js';
18
import { CommandsRegistry, ICommandHandler, ICommandService } from '../../../platform/commands/common/commands.js';
19
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
20
import { ContextKeyExpr, ContextKeyValue, IContextKey, IContextKeyService } from '../../../platform/contextkey/common/contextkey.js';
21
import { IContextMenuService } from '../../../platform/contextview/browser/contextView.js';
22
import { IInstantiationService, ServicesAccessor } from '../../../platform/instantiation/common/instantiation.js';
23
import { IKeybindingService } from '../../../platform/keybinding/common/keybinding.js';
24
import { INotificationService } from '../../../platform/notification/common/notification.js';
25
import { IThemeService } from '../../../platform/theme/common/themeService.js';
26
import { IAccessibilityService } from '../../../platform/accessibility/common/accessibility.js';
27
import { StandaloneCodeEditorNLS } from '../../common/standaloneStrings.js';
28
import { IClipboardService } from '../../../platform/clipboard/common/clipboardService.js';
29
import { IEditorProgressService } from '../../../platform/progress/common/progress.js';
30
import { StandaloneThemeService } from './standaloneThemeService.js';
31
import { IModelService } from '../../common/services/model.js';
32
import { ILanguageSelection, ILanguageService } from '../../common/languages/language.js';
33
import { URI } from '../../../base/common/uri.js';
34
import { StandaloneCodeEditorService } from './standaloneCodeEditorService.js';
35
import { PLAINTEXT_LANGUAGE_ID } from '../../common/languages/modesRegistry.js';
36
import { ILanguageConfigurationService } from '../../common/languages/languageConfigurationRegistry.js';
37
import { IEditorConstructionOptions } from '../../browser/config/editorConfiguration.js';
38
import { ILanguageFeaturesService } from '../../common/services/languageFeatures.js';
39
import { DiffEditorWidget } from '../../browser/widget/diffEditor/diffEditorWidget.js';
40
import { IAccessibilitySignalService } from '../../../platform/accessibilitySignal/browser/accessibilitySignalService.js';
41
import { mainWindow } from '../../../base/browser/window.js';
42
import { setHoverDelegateFactory } from '../../../base/browser/ui/hover/hoverDelegateFactory.js';
43
import { IHoverService, WorkbenchHoverDelegate } from '../../../platform/hover/browser/hover.js';
44
import { setBaseLayerHoverDelegate } from '../../../base/browser/ui/hover/hoverDelegate2.js';
45
import { IMarkdownRendererService } from '../../../platform/markdown/browser/markdownRenderer.js';
46
import { EditorMarkdownCodeBlockRenderer } from '../../browser/widget/markdownRenderer/browser/editorMarkdownCodeBlockRenderer.js';
47
import { IUserInteractionService } from '../../../platform/userInteraction/browser/userInteractionService.js';
48
49
/**
50
* Description of an action contribution
51
*/
52
export interface IActionDescriptor {
53
/**
54
* An unique identifier of the contributed action.
55
*/
56
id: string;
57
/**
58
* A label of the action that will be presented to the user.
59
*/
60
label: string;
61
/**
62
* Precondition rule. The value should be a [context key expression](https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts).
63
*/
64
precondition?: string;
65
/**
66
* An array of keybindings for the action.
67
*/
68
keybindings?: number[];
69
/**
70
* The keybinding rule (condition on top of precondition).
71
*/
72
keybindingContext?: string;
73
/**
74
* Control if the action should show up in the context menu and where.
75
* The context menu of the editor has these default:
76
* navigation - The navigation group comes first in all cases.
77
* 1_modification - This group comes next and contains commands that modify your code.
78
* 9_cutcopypaste - The last default group with the basic editing commands.
79
* You can also create your own group.
80
* Defaults to null (don't show in context menu).
81
*/
82
contextMenuGroupId?: string;
83
/**
84
* Control the order in the context menu group.
85
*/
86
contextMenuOrder?: number;
87
/**
88
* Method that will be executed when the action is triggered.
89
* @param editor The editor instance is passed in as a convenience
90
*/
91
run(editor: ICodeEditor, ...args: unknown[]): void | Promise<void>;
92
}
93
94
/**
95
* Options which apply for all editors.
96
*/
97
export interface IGlobalEditorOptions {
98
/**
99
* The number of spaces a tab is equal to.
100
* This setting is overridden based on the file contents when `detectIndentation` is on.
101
* Defaults to 4.
102
*/
103
tabSize?: number;
104
/**
105
* Insert spaces when pressing `Tab`.
106
* This setting is overridden based on the file contents when `detectIndentation` is on.
107
* Defaults to true.
108
*/
109
insertSpaces?: boolean;
110
/**
111
* Controls whether `tabSize` and `insertSpaces` will be automatically detected when a file is opened based on the file contents.
112
* Defaults to true.
113
*/
114
detectIndentation?: boolean;
115
/**
116
* Remove trailing auto inserted whitespace.
117
* Defaults to true.
118
*/
119
trimAutoWhitespace?: boolean;
120
/**
121
* Special handling for large files to disable certain memory intensive features.
122
* Defaults to true.
123
*/
124
largeFileOptimizations?: boolean;
125
/**
126
* Controls whether completions should be computed based on words in the document.
127
* Defaults to true.
128
*/
129
wordBasedSuggestions?: 'off' | 'currentDocument' | 'matchingDocuments' | 'allDocuments';
130
/**
131
* Controls whether word based completions should be included from opened documents of the same language or any language.
132
*/
133
wordBasedSuggestionsOnlySameLanguage?: boolean;
134
/**
135
* Controls whether the semanticHighlighting is shown for the languages that support it.
136
* true: semanticHighlighting is enabled for all themes
137
* false: semanticHighlighting is disabled for all themes
138
* 'configuredByTheme': semanticHighlighting is controlled by the current color theme's semanticHighlighting setting.
139
* Defaults to 'byTheme'.
140
*/
141
'semanticHighlighting.enabled'?: true | false | 'configuredByTheme';
142
/**
143
* Keep peek editors open even when double-clicking their content or when hitting `Escape`.
144
* Defaults to false.
145
*/
146
stablePeek?: boolean;
147
/**
148
* Lines above this length will not be tokenized for performance reasons.
149
* Defaults to 20000.
150
*/
151
maxTokenizationLineLength?: number;
152
/**
153
* Theme to be used for rendering.
154
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black', 'hc-light'.
155
* You can create custom themes via `monaco.editor.defineTheme`.
156
* To switch a theme, use `monaco.editor.setTheme`.
157
* **NOTE**: The theme might be overwritten if the OS is in high contrast mode, unless `autoDetectHighContrast` is set to false.
158
*/
159
theme?: string;
160
/**
161
* If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme.
162
* Defaults to true.
163
*/
164
autoDetectHighContrast?: boolean;
165
}
166
167
/**
168
* The options to create an editor.
169
*/
170
export interface IStandaloneEditorConstructionOptions extends IEditorConstructionOptions, IGlobalEditorOptions {
171
/**
172
* The initial model associated with this code editor.
173
*/
174
model?: ITextModel | null;
175
/**
176
* The initial value of the auto created model in the editor.
177
* To not automatically create a model, use `model: null`.
178
*/
179
value?: string;
180
/**
181
* The initial language of the auto created model in the editor.
182
* To not automatically create a model, use `model: null`.
183
*/
184
language?: string;
185
/**
186
* Initial theme to be used for rendering.
187
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black', 'hc-light.
188
* You can create custom themes via `monaco.editor.defineTheme`.
189
* To switch a theme, use `monaco.editor.setTheme`.
190
* **NOTE**: The theme might be overwritten if the OS is in high contrast mode, unless `autoDetectHighContrast` is set to false.
191
*/
192
theme?: string;
193
/**
194
* If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme.
195
* Defaults to true.
196
*/
197
autoDetectHighContrast?: boolean;
198
/**
199
* An URL to open when Ctrl+H (Windows and Linux) or Cmd+H (OSX) is pressed in
200
* the accessibility help dialog in the editor.
201
*
202
* Defaults to "https://go.microsoft.com/fwlink/?linkid=852450"
203
*/
204
accessibilityHelpUrl?: string;
205
/**
206
* Container element to use for ARIA messages.
207
* Defaults to document.body.
208
*/
209
ariaContainerElement?: HTMLElement;
210
}
211
212
/**
213
* The options to create a diff editor.
214
*/
215
export interface IStandaloneDiffEditorConstructionOptions extends IDiffEditorConstructionOptions {
216
/**
217
* Initial theme to be used for rendering.
218
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black', 'hc-light.
219
* You can create custom themes via `monaco.editor.defineTheme`.
220
* To switch a theme, use `monaco.editor.setTheme`.
221
* **NOTE**: The theme might be overwritten if the OS is in high contrast mode, unless `autoDetectHighContrast` is set to false.
222
*/
223
theme?: string;
224
/**
225
* If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme.
226
* Defaults to true.
227
*/
228
autoDetectHighContrast?: boolean;
229
}
230
231
export interface IStandaloneCodeEditor extends ICodeEditor {
232
updateOptions(newOptions: IEditorOptions & IGlobalEditorOptions): void;
233
addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null;
234
createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T>;
235
addAction(descriptor: IActionDescriptor): IDisposable;
236
}
237
238
export interface IStandaloneDiffEditor extends IDiffEditor {
239
addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null;
240
createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T>;
241
addAction(descriptor: IActionDescriptor): IDisposable;
242
243
getOriginalEditor(): IStandaloneCodeEditor;
244
getModifiedEditor(): IStandaloneCodeEditor;
245
}
246
247
let LAST_GENERATED_COMMAND_ID = 0;
248
249
let ariaDomNodeCreated = false;
250
/**
251
* Create ARIA dom node inside parent,
252
* or only for the first editor instantiation inside document.body.
253
* @param parent container element for ARIA dom node
254
*/
255
function createAriaDomNode(parent: HTMLElement | undefined) {
256
if (!parent) {
257
if (ariaDomNodeCreated) {
258
return;
259
}
260
ariaDomNodeCreated = true;
261
}
262
aria.setARIAContainer(parent || mainWindow.document.body);
263
}
264
265
/**
266
* A code editor to be used both by the standalone editor and the standalone diff editor.
267
*/
268
export class StandaloneCodeEditor extends CodeEditorWidget implements IStandaloneCodeEditor {
269
270
private readonly _standaloneKeybindingService: StandaloneKeybindingService | null;
271
272
constructor(
273
domElement: HTMLElement,
274
_options: Readonly<IStandaloneEditorConstructionOptions>,
275
@IInstantiationService instantiationService: IInstantiationService,
276
@ICodeEditorService codeEditorService: ICodeEditorService,
277
@ICommandService commandService: ICommandService,
278
@IContextKeyService contextKeyService: IContextKeyService,
279
@IHoverService hoverService: IHoverService,
280
@IKeybindingService keybindingService: IKeybindingService,
281
@IThemeService themeService: IThemeService,
282
@INotificationService notificationService: INotificationService,
283
@IAccessibilityService accessibilityService: IAccessibilityService,
284
@ILanguageConfigurationService languageConfigurationService: ILanguageConfigurationService,
285
@ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService,
286
@IMarkdownRendererService markdownRendererService: IMarkdownRendererService,
287
@IUserInteractionService userInteractionService: IUserInteractionService,
288
) {
289
const options = { ..._options };
290
options.ariaLabel = options.ariaLabel || StandaloneCodeEditorNLS.editorViewAccessibleLabel;
291
super(domElement, options, {}, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService, userInteractionService);
292
293
if (keybindingService instanceof StandaloneKeybindingService) {
294
this._standaloneKeybindingService = keybindingService;
295
} else {
296
this._standaloneKeybindingService = null;
297
}
298
299
createAriaDomNode(options.ariaContainerElement);
300
301
setHoverDelegateFactory((placement, enableInstantHover) => instantiationService.createInstance(WorkbenchHoverDelegate, placement, { instantHover: enableInstantHover }, {}));
302
setBaseLayerHoverDelegate(hoverService);
303
304
markdownRendererService.setDefaultCodeBlockRenderer(instantiationService.createInstance(EditorMarkdownCodeBlockRenderer));
305
}
306
307
public addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null {
308
if (!this._standaloneKeybindingService) {
309
console.warn('Cannot add command because the editor is configured with an unrecognized KeybindingService');
310
return null;
311
}
312
const commandId = 'DYNAMIC_' + (++LAST_GENERATED_COMMAND_ID);
313
const whenExpression = ContextKeyExpr.deserialize(context);
314
this._standaloneKeybindingService.addDynamicKeybinding(commandId, keybinding, handler, whenExpression);
315
return commandId;
316
}
317
318
public createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T> {
319
return this._contextKeyService.createKey(key, defaultValue);
320
}
321
322
public addAction(_descriptor: IActionDescriptor): IDisposable {
323
if ((typeof _descriptor.id !== 'string') || (typeof _descriptor.label !== 'string') || (typeof _descriptor.run !== 'function')) {
324
throw new Error('Invalid action descriptor, `id`, `label` and `run` are required properties!');
325
}
326
if (!this._standaloneKeybindingService) {
327
console.warn('Cannot add keybinding because the editor is configured with an unrecognized KeybindingService');
328
return Disposable.None;
329
}
330
331
// Read descriptor options
332
const id = _descriptor.id;
333
const label = _descriptor.label;
334
const precondition = ContextKeyExpr.and(
335
ContextKeyExpr.equals('editorId', this.getId()),
336
ContextKeyExpr.deserialize(_descriptor.precondition)
337
);
338
const keybindings = _descriptor.keybindings;
339
const keybindingsWhen = ContextKeyExpr.and(
340
precondition,
341
ContextKeyExpr.deserialize(_descriptor.keybindingContext)
342
);
343
const contextMenuGroupId = _descriptor.contextMenuGroupId || null;
344
const contextMenuOrder = _descriptor.contextMenuOrder || 0;
345
const run = (_accessor?: ServicesAccessor, ...args: unknown[]): Promise<void> => {
346
return Promise.resolve(_descriptor.run(this, ...args));
347
};
348
349
350
const toDispose = new DisposableStore();
351
352
// Generate a unique id to allow the same descriptor.id across multiple editor instances
353
const uniqueId = this.getId() + ':' + id;
354
355
// Register the command
356
toDispose.add(CommandsRegistry.registerCommand(uniqueId, run));
357
358
// Register the context menu item
359
if (contextMenuGroupId) {
360
const menuItem: IMenuItem = {
361
command: {
362
id: uniqueId,
363
title: label
364
},
365
when: precondition,
366
group: contextMenuGroupId,
367
order: contextMenuOrder
368
};
369
toDispose.add(MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem));
370
}
371
372
// Register the keybindings
373
if (Array.isArray(keybindings)) {
374
for (const kb of keybindings) {
375
toDispose.add(this._standaloneKeybindingService.addDynamicKeybinding(uniqueId, kb, run, keybindingsWhen));
376
}
377
}
378
379
// Finally, register an internal editor action
380
const internalAction = new InternalEditorAction(
381
uniqueId,
382
label,
383
label,
384
undefined,
385
precondition,
386
(...args: unknown[]) => Promise.resolve(_descriptor.run(this, ...args)),
387
this._contextKeyService
388
);
389
390
// Store it under the original id, such that trigger with the original id will work
391
this._actions.set(id, internalAction);
392
toDispose.add(toDisposable(() => {
393
this._actions.delete(id);
394
}));
395
396
return toDispose;
397
}
398
399
protected override _triggerCommand(handlerId: string, payload: unknown): void {
400
if (this._codeEditorService instanceof StandaloneCodeEditorService) {
401
// Help commands find this editor as the active editor
402
try {
403
this._codeEditorService.setActiveCodeEditor(this);
404
super._triggerCommand(handlerId, payload);
405
} finally {
406
this._codeEditorService.setActiveCodeEditor(null);
407
}
408
} else {
409
super._triggerCommand(handlerId, payload);
410
}
411
}
412
}
413
414
export class StandaloneEditor extends StandaloneCodeEditor implements IStandaloneCodeEditor {
415
416
private readonly _configurationService: IConfigurationService;
417
private readonly _standaloneThemeService: IStandaloneThemeService;
418
private _ownsModel: boolean;
419
420
constructor(
421
domElement: HTMLElement,
422
_options: Readonly<IStandaloneEditorConstructionOptions> | undefined,
423
@IInstantiationService instantiationService: IInstantiationService,
424
@ICodeEditorService codeEditorService: ICodeEditorService,
425
@ICommandService commandService: ICommandService,
426
@IContextKeyService contextKeyService: IContextKeyService,
427
@IHoverService hoverService: IHoverService,
428
@IKeybindingService keybindingService: IKeybindingService,
429
@IStandaloneThemeService themeService: IStandaloneThemeService,
430
@INotificationService notificationService: INotificationService,
431
@IConfigurationService configurationService: IConfigurationService,
432
@IAccessibilityService accessibilityService: IAccessibilityService,
433
@IModelService modelService: IModelService,
434
@ILanguageService languageService: ILanguageService,
435
@ILanguageConfigurationService languageConfigurationService: ILanguageConfigurationService,
436
@ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService,
437
@IMarkdownRendererService markdownRendererService: IMarkdownRendererService,
438
@IUserInteractionService userInteractionService: IUserInteractionService,
439
) {
440
const options = { ..._options };
441
updateConfigurationService(configurationService, options, false);
442
const themeDomRegistration = (<StandaloneThemeService>themeService).registerEditorContainer(domElement);
443
if (typeof options.theme === 'string') {
444
themeService.setTheme(options.theme);
445
}
446
if (typeof options.autoDetectHighContrast !== 'undefined') {
447
themeService.setAutoDetectHighContrast(Boolean(options.autoDetectHighContrast));
448
}
449
const _model: ITextModel | null | undefined = options.model;
450
delete options.model;
451
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, hoverService, keybindingService, themeService, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService, markdownRendererService, userInteractionService);
452
453
this._configurationService = configurationService;
454
this._standaloneThemeService = themeService;
455
this._register(themeDomRegistration);
456
457
let model: ITextModel | null;
458
if (typeof _model === 'undefined') {
459
const languageId = languageService.getLanguageIdByMimeType(options.language) || options.language || PLAINTEXT_LANGUAGE_ID;
460
model = createTextModel(modelService, languageService, options.value || '', languageId, undefined);
461
this._ownsModel = true;
462
} else {
463
model = _model;
464
this._ownsModel = false;
465
}
466
467
this._attachModel(model);
468
if (model) {
469
const e: IModelChangedEvent = {
470
oldModelUrl: null,
471
newModelUrl: model.uri
472
};
473
this._onDidChangeModel.fire(e);
474
}
475
}
476
477
public override dispose(): void {
478
super.dispose();
479
}
480
481
public override updateOptions(newOptions: Readonly<IEditorOptions & IGlobalEditorOptions>): void {
482
updateConfigurationService(this._configurationService, newOptions, false);
483
if (typeof newOptions.theme === 'string') {
484
this._standaloneThemeService.setTheme(newOptions.theme);
485
}
486
if (typeof newOptions.autoDetectHighContrast !== 'undefined') {
487
this._standaloneThemeService.setAutoDetectHighContrast(Boolean(newOptions.autoDetectHighContrast));
488
}
489
super.updateOptions(newOptions);
490
}
491
492
protected override _postDetachModelCleanup(detachedModel: ITextModel): void {
493
super._postDetachModelCleanup(detachedModel);
494
if (detachedModel && this._ownsModel) {
495
detachedModel.dispose();
496
this._ownsModel = false;
497
}
498
}
499
}
500
501
export class StandaloneDiffEditor2 extends DiffEditorWidget implements IStandaloneDiffEditor {
502
503
private readonly _configurationService: IConfigurationService;
504
private readonly _standaloneThemeService: IStandaloneThemeService;
505
506
constructor(
507
domElement: HTMLElement,
508
_options: Readonly<IStandaloneDiffEditorConstructionOptions> | undefined,
509
@IInstantiationService instantiationService: IInstantiationService,
510
@IContextKeyService contextKeyService: IContextKeyService,
511
@ICodeEditorService codeEditorService: ICodeEditorService,
512
@IStandaloneThemeService themeService: IStandaloneThemeService,
513
@INotificationService notificationService: INotificationService,
514
@IConfigurationService configurationService: IConfigurationService,
515
@IContextMenuService contextMenuService: IContextMenuService,
516
@IEditorProgressService editorProgressService: IEditorProgressService,
517
@IClipboardService clipboardService: IClipboardService,
518
@IAccessibilitySignalService accessibilitySignalService: IAccessibilitySignalService,
519
) {
520
const options = { ..._options };
521
updateConfigurationService(configurationService, options, true);
522
const themeDomRegistration = (<StandaloneThemeService>themeService).registerEditorContainer(domElement);
523
if (typeof options.theme === 'string') {
524
themeService.setTheme(options.theme);
525
}
526
if (typeof options.autoDetectHighContrast !== 'undefined') {
527
themeService.setAutoDetectHighContrast(Boolean(options.autoDetectHighContrast));
528
}
529
530
super(
531
domElement,
532
options,
533
{},
534
contextKeyService,
535
instantiationService,
536
codeEditorService,
537
accessibilitySignalService,
538
editorProgressService,
539
);
540
541
this._configurationService = configurationService;
542
this._standaloneThemeService = themeService;
543
544
this._register(themeDomRegistration);
545
}
546
547
public override dispose(): void {
548
super.dispose();
549
}
550
551
public override updateOptions(newOptions: Readonly<IDiffEditorOptions & IGlobalEditorOptions>): void {
552
updateConfigurationService(this._configurationService, newOptions, true);
553
if (typeof newOptions.theme === 'string') {
554
this._standaloneThemeService.setTheme(newOptions.theme);
555
}
556
if (typeof newOptions.autoDetectHighContrast !== 'undefined') {
557
this._standaloneThemeService.setAutoDetectHighContrast(Boolean(newOptions.autoDetectHighContrast));
558
}
559
super.updateOptions(newOptions);
560
}
561
562
protected override _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: Readonly<IEditorOptions>): CodeEditorWidget {
563
return instantiationService.createInstance(StandaloneCodeEditor, container, options);
564
}
565
566
public override getOriginalEditor(): IStandaloneCodeEditor {
567
return <StandaloneCodeEditor>super.getOriginalEditor();
568
}
569
570
public override getModifiedEditor(): IStandaloneCodeEditor {
571
return <StandaloneCodeEditor>super.getModifiedEditor();
572
}
573
574
public addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null {
575
return this.getModifiedEditor().addCommand(keybinding, handler, context);
576
}
577
578
public createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T> {
579
return this.getModifiedEditor().createContextKey(key, defaultValue);
580
}
581
582
public addAction(descriptor: IActionDescriptor): IDisposable {
583
return this.getModifiedEditor().addAction(descriptor);
584
}
585
}
586
587
/**
588
* @internal
589
*/
590
export function createTextModel(modelService: IModelService, languageService: ILanguageService, value: string, languageId: string | undefined, uri: URI | undefined): ITextModel {
591
value = value || '';
592
if (!languageId) {
593
const firstLF = value.indexOf('\n');
594
let firstLine = value;
595
if (firstLF !== -1) {
596
firstLine = value.substring(0, firstLF);
597
}
598
return doCreateModel(modelService, value, languageService.createByFilepathOrFirstLine(uri || null, firstLine), uri);
599
}
600
return doCreateModel(modelService, value, languageService.createById(languageId), uri);
601
}
602
603
/**
604
* @internal
605
*/
606
function doCreateModel(modelService: IModelService, value: string, languageSelection: ILanguageSelection, uri: URI | undefined): ITextModel {
607
return modelService.createModel(value, languageSelection, uri);
608
}
609
610