提交 b18ef0e7 编写于 作者: M Matt Bierner

Make `getFocusedCodeEditor` return undefined instead of null

#70384
上级 5aee2f0a
......@@ -70,8 +70,8 @@ export abstract class AbstractCodeEditorService extends Disposable implements IC
return Object.keys(this._diffEditors).map(id => this._diffEditors[id]);
}
getFocusedCodeEditor(): ICodeEditor | null {
let editorWithWidgetFocus: ICodeEditor | null = null;
getFocusedCodeEditor(): ICodeEditor | undefined {
let editorWithWidgetFocus: ICodeEditor | undefined;
const editors = this.listCodeEditors();
for (const editor of editors) {
......
......@@ -33,9 +33,10 @@ export interface ICodeEditorService {
listDiffEditors(): IDiffEditor[];
/**
* Returns the current focused code editor (if the focus is in the editor or in an editor widget) or null.
* Returns the current focused code editor (if the focus is in the editor or in an editor widget) or
* `undefined` if none.
*/
getFocusedCodeEditor(): ICodeEditor | null;
getFocusedCodeEditor(): ICodeEditor | undefined;
registerDecorationType(key: string, options: IDecorationRenderOptions, parentTypeKey?: string): void;
removeDecorationType(key: string): void;
......
......@@ -14,6 +14,7 @@ import { URI } from 'vs/base/common/uri';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import { IOpener, IOpenerService, IValidator, IExternalUriResolver } from 'vs/platform/opener/common/opener';
import { withUndefinedAsNull } from 'vs/base/common/types';
export class OpenerService extends Disposable implements IOpenerService {
......@@ -118,7 +119,7 @@ export class OpenerService extends Disposable implements IOpenerService {
return this._editorService.openCodeEditor(
{ resource, options: { selection, } },
this._editorService.getFocusedCodeEditor(),
withUndefinedAsNull(this._editorService.getFocusedCodeEditor()),
options && options.openToSide
).then(() => true);
}
......
......@@ -57,8 +57,8 @@ export namespace PeekContext {
export const notInPeekEditor: ContextKeyExpr = inPeekEditor.toNegated();
}
export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor | null {
let editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor | undefined {
const editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
if (editor instanceof EmbeddedCodeEditorWidget) {
return editor.getParentEditor();
}
......
......@@ -28,6 +28,7 @@ import { URI } from 'vs/base/common/uri';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { CancellationToken } from 'vs/base/common/cancellation';
import { coalesce, flatten } from 'vs/base/common/arrays';
import { withUndefinedAsNull } from 'vs/base/common/types';
export const defaultReferenceSearchOptions: RequestOptions = {
getMetaTitle(model) {
......@@ -106,7 +107,7 @@ let findReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour
}
const codeEditorService = accessor.get(ICodeEditorService);
return codeEditorService.openCodeEditor({ resource }, codeEditorService.getFocusedCodeEditor()).then(control => {
return codeEditorService.openCodeEditor({ resource }, withUndefinedAsNull(codeEditorService.getFocusedCodeEditor())).then(control => {
if (!isCodeEditor(control) || !control.hasModel()) {
return undefined;
}
......@@ -132,7 +133,7 @@ let showReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour
}
const codeEditorService = accessor.get(ICodeEditorService);
return codeEditorService.openCodeEditor({ resource }, codeEditorService.getFocusedCodeEditor()).then(control => {
return codeEditorService.openCodeEditor({ resource }, withUndefinedAsNull(codeEditorService.getFocusedCodeEditor())).then(control => {
if (!isCodeEditor(control)) {
return undefined;
}
......
......@@ -149,7 +149,7 @@ function getChangeTypeColor(theme: ITheme, changeType: ChangeType): Color | unde
}
}
function getOuterEditorFromDiffEditor(accessor: ServicesAccessor): ICodeEditor | null {
function getOuterEditorFromDiffEditor(accessor: ServicesAccessor): ICodeEditor | undefined {
const diffEditors = accessor.get(ICodeEditorService).listDiffEditors();
for (const diffEditor of diffEditors) {
......
......@@ -1167,7 +1167,7 @@ export class TestCodeEditorService implements ICodeEditorService {
addDiffEditor(_editor: IDiffEditor): void { }
removeDiffEditor(_editor: IDiffEditor): void { }
listDiffEditors(): IDiffEditor[] { return []; }
getFocusedCodeEditor(): ICodeEditor | null { return null; }
getFocusedCodeEditor(): ICodeEditor | undefined { return undefined; }
registerDecorationType(_key: string, _options: IDecorationRenderOptions, _parentTypeKey?: string): void { }
removeDecorationType(_key: string): void { }
resolveDecorationOptions(_typeKey: string, _writable: boolean): IModelDecorationOptions { return Object.create(null); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册