This commit is contained in:
Alex Dima 2021-05-12 16:57:19 +02:00
parent 1f76da28f6
commit a53919b8e9
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
3 changed files with 27 additions and 2 deletions

View file

@ -226,7 +226,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
protected readonly _instantiationService: IInstantiationService;
protected readonly _contextKeyService: IContextKeyService;
private readonly _notificationService: INotificationService;
private readonly _codeEditorService: ICodeEditorService;
protected readonly _codeEditorService: ICodeEditorService;
private readonly _commandService: ICommandService;
private readonly _themeService: IThemeService;
@ -1048,6 +1048,10 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
return;
}
this._triggerCommand(handlerId, payload);
}
protected _triggerCommand(handlerId: string, payload: any): void {
this._commandService.executeCommand(handlerId, payload);
}

View file

@ -34,6 +34,7 @@ import { StandaloneThemeServiceImpl } from 'vs/editor/standalone/browser/standal
import { IModelService } from 'vs/editor/common/services/modelService';
import { ILanguageSelection, IModeService } from 'vs/editor/common/services/modeService';
import { URI } from 'vs/base/common/uri';
import { StandaloneCodeEditorServiceImpl } from 'vs/editor/standalone/browser/standaloneCodeServiceImpl';
/**
* Description of an action contribution
@ -363,6 +364,20 @@ export class StandaloneCodeEditor extends CodeEditorWidget implements IStandalon
return toDispose;
}
protected override _triggerCommand(handlerId: string, payload: any): void {
if (this._codeEditorService instanceof StandaloneCodeEditorServiceImpl) {
// Help commands find this editor as the active editor
try {
this._codeEditorService.setActiveCodeEditor(this);
super._triggerCommand(handlerId, payload);
} finally {
this._codeEditorService.setActiveCodeEditor(null);
}
} else {
super._triggerCommand(handlerId, payload);
}
}
}
export class StandaloneEditor extends StandaloneCodeEditor implements IStandaloneCodeEditor {

View file

@ -18,6 +18,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl {
private readonly _editorIsOpen: IContextKey<boolean>;
private _activeCodeEditor: ICodeEditor | null;
constructor(
styleSheet: GlobalStyleSheet | null,
@ -28,6 +29,7 @@ export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl {
this.onCodeEditorAdd(() => this._checkContextKey());
this.onCodeEditorRemove(() => this._checkContextKey());
this._editorIsOpen = contextKeyService.createKey('editorIsOpen', false);
this._activeCodeEditor = null;
}
private _checkContextKey(): void {
@ -41,8 +43,12 @@ export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl {
this._editorIsOpen.set(hasCodeEditor);
}
public setActiveCodeEditor(activeCodeEditor: ICodeEditor | null): void {
this._activeCodeEditor = activeCodeEditor;
}
public getActiveCodeEditor(): ICodeEditor | null {
return null; // not supported in the standalone case
return this._activeCodeEditor;
}
public openCodeEditor(input: IResourceEditorInput, source: ICodeEditor | null, sideBySide?: boolean): Promise<ICodeEditor | null> {