Skip to content

Commit bbb5799

Browse files
committed
Make new diff editor available in monaco (with experimental.useVersion2: true)
1 parent 6d45c36 commit bbb5799

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

src/vs/editor/standalone/browser/standaloneCodeEditor.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry'
3737
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
3838
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
3939
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
40+
import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';
4041

4142
/**
4243
* Description of an action contribution
@@ -555,6 +556,89 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
555556
}
556557
}
557558

559+
export class StandaloneDiffEditor2 extends DiffEditorWidget2 implements IStandaloneDiffEditor {
560+
561+
private readonly _configurationService: IConfigurationService;
562+
private readonly _standaloneThemeService: IStandaloneThemeService;
563+
564+
constructor(
565+
domElement: HTMLElement,
566+
_options: Readonly<IStandaloneDiffEditorConstructionOptions> | undefined,
567+
@IInstantiationService instantiationService: IInstantiationService,
568+
@IContextKeyService contextKeyService: IContextKeyService,
569+
@ICodeEditorService codeEditorService: ICodeEditorService,
570+
@IStandaloneThemeService themeService: IStandaloneThemeService,
571+
@INotificationService notificationService: INotificationService,
572+
@IConfigurationService configurationService: IConfigurationService,
573+
@IContextMenuService contextMenuService: IContextMenuService,
574+
@IEditorProgressService editorProgressService: IEditorProgressService,
575+
@IClipboardService clipboardService: IClipboardService
576+
) {
577+
const options = { ..._options };
578+
updateConfigurationService(configurationService, options, true);
579+
const themeDomRegistration = (<StandaloneThemeService>themeService).registerEditorContainer(domElement);
580+
if (typeof options.theme === 'string') {
581+
themeService.setTheme(options.theme);
582+
}
583+
if (typeof options.autoDetectHighContrast !== 'undefined') {
584+
themeService.setAutoDetectHighContrast(Boolean(options.autoDetectHighContrast));
585+
}
586+
587+
super(
588+
domElement,
589+
options,
590+
{},
591+
contextKeyService,
592+
instantiationService,
593+
codeEditorService,
594+
);
595+
596+
this._configurationService = configurationService;
597+
this._standaloneThemeService = themeService;
598+
599+
this._register(themeDomRegistration);
600+
}
601+
602+
public override dispose(): void {
603+
super.dispose();
604+
}
605+
606+
public override updateOptions(newOptions: Readonly<IDiffEditorOptions & IGlobalEditorOptions>): void {
607+
updateConfigurationService(this._configurationService, newOptions, true);
608+
if (typeof newOptions.theme === 'string') {
609+
this._standaloneThemeService.setTheme(newOptions.theme);
610+
}
611+
if (typeof newOptions.autoDetectHighContrast !== 'undefined') {
612+
this._standaloneThemeService.setAutoDetectHighContrast(Boolean(newOptions.autoDetectHighContrast));
613+
}
614+
super.updateOptions(newOptions);
615+
}
616+
617+
protected override _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: Readonly<IEditorOptions>): CodeEditorWidget {
618+
return instantiationService.createInstance(StandaloneCodeEditor, container, options);
619+
}
620+
621+
public override getOriginalEditor(): IStandaloneCodeEditor {
622+
return <StandaloneCodeEditor>super.getOriginalEditor();
623+
}
624+
625+
public override getModifiedEditor(): IStandaloneCodeEditor {
626+
return <StandaloneCodeEditor>super.getModifiedEditor();
627+
}
628+
629+
public addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null {
630+
return this.getModifiedEditor().addCommand(keybinding, handler, context);
631+
}
632+
633+
public createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T> {
634+
return this.getModifiedEditor().createContextKey(key, defaultValue);
635+
}
636+
637+
public addAction(descriptor: IActionDescriptor): IDisposable {
638+
return this.getModifiedEditor().addAction(descriptor);
639+
}
640+
}
641+
558642
/**
559643
* @internal
560644
*/

src/vs/editor/standalone/browser/standaloneEditor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { IModelService } from 'vs/editor/common/services/model';
2323
import { createWebWorker as actualCreateWebWorker, IWebWorkerOptions, MonacoWebWorker } from 'vs/editor/browser/services/webWorker';
2424
import * as standaloneEnums from 'vs/editor/common/standalone/standaloneEnums';
2525
import { Colorizer, IColorizerElementOptions, IColorizerOptions } from 'vs/editor/standalone/browser/colorizer';
26-
import { createTextModel, IActionDescriptor, IStandaloneCodeEditor, IStandaloneDiffEditor, IStandaloneDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, StandaloneDiffEditor, StandaloneEditor } from 'vs/editor/standalone/browser/standaloneCodeEditor';
26+
import { createTextModel, IActionDescriptor, IStandaloneCodeEditor, IStandaloneDiffEditor, IStandaloneDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, StandaloneDiffEditor, StandaloneDiffEditor2, StandaloneEditor } from 'vs/editor/standalone/browser/standaloneCodeEditor';
2727
import { IEditorOverrideServices, StandaloneKeybindingService, StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices';
2828
import { StandaloneThemeService } from 'vs/editor/standalone/browser/standaloneThemeService';
2929
import { IStandaloneThemeData, IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneTheme';
@@ -98,6 +98,9 @@ export function getDiffEditors(): readonly IDiffEditor[] {
9898
*/
9999
export function createDiffEditor(domElement: HTMLElement, options?: IStandaloneDiffEditorConstructionOptions, override?: IEditorOverrideServices): IStandaloneDiffEditor {
100100
const instantiationService = StandaloneServices.initialize(override || {});
101+
if ((options?.experimental as any)?.useVersion2) {
102+
return instantiationService.createInstance(StandaloneDiffEditor2, domElement, options);
103+
}
101104
return instantiationService.createInstance(StandaloneDiffEditor, domElement, options);
102105
}
103106

0 commit comments

Comments
 (0)