From 8cb8c024101665639ea81ba759de486a6b3f1d00 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 18 May 2018 09:54:14 +0200 Subject: [PATCH] grid - cleanup getCodeEditor() --- src/vs/editor/browser/editorBrowser.ts | 15 ++++++++ .../browser/services/codeEditorService.ts | 35 +------------------ .../browser/parts/editor/editorActions.ts | 8 ++--- .../parts/editor/editorGroupsControl.ts | 4 +-- .../browser/parts/editor/editorPart.ts | 5 ++- .../browser/parts/editor/editorStatus.ts | 32 ++++++++--------- .../browser/parts/editor/textEditor.ts | 7 ++-- .../browser/parts/editor2/editor2.ts | 8 ++--- .../browser/parts/editor2/nextTitleControl.ts | 5 ++- .../files/electron-browser/fileCommands.ts | 11 +++--- .../history/electron-browser/history.ts | 20 +++++------ .../preferences/browser/preferencesService.ts | 17 ++++----- 12 files changed, 71 insertions(+), 96 deletions(-) diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index 104653a4eca..559d6cdfc1e 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -839,3 +839,18 @@ export function isDiffEditor(thing: any): thing is IDiffEditor { return false; } } + +/** + *@internal + */ +export function getCodeEditor(thing: any): ICodeEditor { + if (isCodeEditor(thing)) { + return thing; + } + + if (isDiffEditor(thing)) { + return thing.getModifiedEditor(); + } + + return null; +} \ No newline at end of file diff --git a/src/vs/editor/browser/services/codeEditorService.ts b/src/vs/editor/browser/services/codeEditorService.ts index 69972231ce7..26dbbe2aab8 100644 --- a/src/vs/editor/browser/services/codeEditorService.ts +++ b/src/vs/editor/browser/services/codeEditorService.ts @@ -8,7 +8,7 @@ import { Event } from 'vs/base/common/event'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon'; import { IModelDecorationOptions, ITextModel } from 'vs/editor/common/model'; -import { ICodeEditor, IDiffEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; +import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IResourceInput } from 'vs/platform/editor/common/editor'; import { TPromise } from 'vs/base/common/winjs.base'; @@ -46,36 +46,3 @@ export interface ICodeEditorService { getActiveCodeEditor(): ICodeEditor; openCodeEditor(input: IResourceInput, source: ICodeEditor, sideBySide?: boolean): TPromise; } - -/** - * Uses `editor.getControl()` and returns either the code editor, or the modified editor of a diff editor or nothing. - */ -export function getCodeEditor(editor: { getControl: () => any }): ICodeEditor { - let r = getCodeOrDiffEditor(editor); - return r.codeEditor || (r.diffEditor && r.diffEditor.getModifiedEditor()) || null; -} - -function getCodeOrDiffEditor(editor: { getControl: () => any }): { codeEditor: ICodeEditor; diffEditor: IDiffEditor } { - if (editor) { - let control = editor.getControl(); - if (control) { - if (isCodeEditor(control)) { - return { - codeEditor: control, - diffEditor: null - }; - } - if (isDiffEditor(control)) { - return { - codeEditor: null, - diffEditor: control - }; - } - } - } - - return { - codeEditor: null, - diffEditor: null - }; -} diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index 0cbf48c6cff..76672b9463f 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -8,7 +8,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import * as nls from 'vs/nls'; import { Action } from 'vs/base/common/actions'; import { mixin } from 'vs/base/common/objects'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; +import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { IEditor, IEditorInput, EditorInput, TextEditorOptions, EditorOptions, IEditorIdentifier, ConfirmResult, IEditorCommandsContext, GroupIdentifier, groupFromContext, CloseDirection } from 'vs/workbench/common/editor'; import { QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel'; import { EditorQuickOpenEntry, EditorQuickOpenEntryGroup, IEditorQuickOpenEntry, QuickOpenAction } from 'vs/workbench/browser/quickopen'; @@ -62,7 +62,7 @@ export class SplitEditorAction extends Action { // Options let options: EditorOptions; - const codeEditor = getCodeEditor(editorToSplit); + const codeEditor = getCodeEditor(editorToSplit.getControl()); if (codeEditor) { options = TextEditorOptions.fromEditor(codeEditor); } else { @@ -143,7 +143,7 @@ export class BaseSplitEditorGroupAction extends Action { // Open editor if (activeEditor) { let options: EditorOptions; - const codeEditor = getCodeEditor(group.activeControl); + const codeEditor = getCodeEditor(group.activeControl.getControl()); if (codeEditor) { options = TextEditorOptions.fromEditor(codeEditor); } else { @@ -411,7 +411,7 @@ export abstract class BaseFocusSideGroupAction extends Action { // Options let options: EditorOptions; - const codeEditor = getCodeEditor(referenceEditor); + const codeEditor = getCodeEditor(referenceEditor.getControl()); if (codeEditor) { options = TextEditorOptions.fromEditor(codeEditor, { pinned: true }); } else { diff --git a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts index 03ce531b9a8..3ecae059978 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts @@ -27,7 +27,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { IEditorStacksModel, IStacksModelChangeEvent, IEditorGroup, EditorOptions, TextEditorOptions, IEditorIdentifier, EditorInput } from 'vs/workbench/common/editor'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; +import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { editorBackground, contrastBorder, activeContrastBorder } from 'vs/platform/theme/common/colorRegistry'; import { Themable, EDITOR_GROUP_HEADER_TABS_BACKGROUND, EDITOR_GROUP_HEADER_NO_TABS_BACKGROUND, EDITOR_GROUP_BORDER, EDITOR_DRAG_AND_DROP_BACKGROUND, EDITOR_GROUP_HEADER_TABS_BORDER } from 'vs/workbench/common/theme'; @@ -1134,7 +1134,7 @@ export class EditorGroupsControl extends Themable implements IEditorGroupsContro // for th editor to be a text editor and creating the options accordingly if so let options = EditorOptions.create({ pinned: true }); const activeEditor = $this.editorService.getActiveEditor(); - const editor = getCodeEditor(activeEditor); + const editor = getCodeEditor(activeEditor.getControl()); if (editor && activeEditor.group.id === stacks.positionOfGroup(stacks.getGroup(identifier.groupId)) && identifier.editor.matches(activeEditor.input)) { options = TextEditorOptions.fromEditor(editor, { pinned: true }); } diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index e488b935122..04fa2328acc 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -15,7 +15,6 @@ import * as arrays from 'vs/base/common/arrays'; import * as types from 'vs/base/common/types'; import * as errors from 'vs/base/common/errors'; import * as objects from 'vs/base/common/objects'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; import { toErrorMessage } from 'vs/base/common/errorMessage'; import { Scope as MementoScope } from 'vs/workbench/common/memento'; import { Part } from 'vs/workbench/browser/part'; @@ -43,7 +42,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { join } from 'vs/base/common/paths'; import { IEditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor'; import { ThrottledEmitter } from 'vs/base/common/async'; -import { isCodeEditor } from 'vs/editor/browser/editorBrowser'; +import { isCodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { INotificationService, Severity, INotificationActions } from 'vs/platform/notification/common/notification'; import { dispose } from 'vs/base/common/lifecycle'; @@ -758,7 +757,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService // for the editor to be a text editor and creating the options accordingly if so let options = EditorOptions.create({ pinned: true, index, inactive, preserveFocus }); const activeEditor = this.getActiveEditor(); - const codeEditor = getCodeEditor(activeEditor); + const codeEditor = getCodeEditor(activeEditor.getControl()); if (codeEditor && activeEditor.group === this.stacks.positionOfGroup(fromGroup) && input.matches(activeEditor.input)) { options = TextEditorOptions.fromEditor(codeEditor, { pinned: true, index, inactive, preserveFocus }); } diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 1dbbc21b347..8642540db42 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -42,7 +42,6 @@ import { TabFocus } from 'vs/editor/common/config/commonEditorConfig'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { getCodeEditor as getEditorWidget } from 'vs/editor/browser/services/codeEditorService'; import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { IConfigurationChangedEvent, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; @@ -52,7 +51,7 @@ import { attachButtonStyler } from 'vs/platform/theme/common/styler'; import { widgetShadow, editorWidgetBackground, foreground, darken, contrastBorder } from 'vs/platform/theme/common/colorRegistry'; import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { deepClone } from 'vs/base/common/objects'; -import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; +import { ICodeEditor, isCodeEditor, isDiffEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { Button } from 'vs/base/browser/ui/button/button'; import { Schemas } from 'vs/base/common/network'; import { IAnchor } from 'vs/base/browser/ui/contextview/contextview'; @@ -545,7 +544,7 @@ export class EditorStatus implements IStatusbarItem { private updateStatusBar(): void { const activeControl = this.editorService.activeControl; - const activeCodeEditor = getEditorWidget(activeControl); + const activeCodeEditor = activeControl ? getCodeEditor(activeControl.getControl()) : void 0; // Update all states this.onScreenReaderModeChange(activeCodeEditor); @@ -748,7 +747,7 @@ export class EditorStatus implements IStatusbarItem { const info: StateDelta = { encoding: null }; // We only support text based editors - if (getEditorWidget(e)) { + if (isCodeEditor(e.getControl()) || isDiffEditor(e.getControl())) { const encodingSupport: IEncodingSupport = toEditorWithEncodingSupport(e.input); if (encodingSupport) { const rawEncoding = encodingSupport.getEncoding(); @@ -796,7 +795,7 @@ function isWritableCodeEditor(codeEditor: ICodeEditor): boolean { } function isWritableBaseEditor(e: IBaseEditor): boolean { - return isWritableCodeEditor(getEditorWidget(e)); + return e && isWritableCodeEditor(getCodeEditor(e.getControl())); } export class ShowLanguageExtensionsAction extends Action { @@ -839,14 +838,13 @@ export class ChangeModeAction extends Action { } public run(): TPromise { - let activeControl = this.editorService.activeControl; - const activeCodeEditor = getEditorWidget(activeControl); + const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorControl); if (!activeCodeEditor) { return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); } const textModel = activeCodeEditor.getModel(); - const resource = toResource(activeControl.input, { supportSideBySide: true }); + const resource = toResource(this.editorService.activeEditor, { supportSideBySide: true }); let hasLanguageSupport = !!resource; if (resource.scheme === Schemas.untitled && !this.untitledEditorService.hasAssociatedFilePath(resource)) { @@ -944,7 +942,7 @@ export class ChangeModeAction extends Action { } // Change mode for active editor - activeControl = this.editorService.activeControl; + const activeEditor = this.editorService.activeEditor; const codeOrDiffEditor = this.editorService.activeTextEditorControl; const models: ITextModel[] = []; if (isCodeEditor(codeOrDiffEditor)) { @@ -967,7 +965,7 @@ export class ChangeModeAction extends Action { // Find mode let mode: TPromise; if (pick === autoDetectMode) { - mode = this.modeService.getOrCreateModeByFilenameOrFirstLine(toResource(activeControl.input, { supportSideBySide: true }).fsPath, textModel.getLineContent(1)); + mode = this.modeService.getOrCreateModeByFilenameOrFirstLine(toResource(activeEditor, { supportSideBySide: true }).fsPath, textModel.getLineContent(1)); } else { mode = this.modeService.getOrCreateModeByLanguageName(pick.label); } @@ -1047,11 +1045,11 @@ class ChangeIndentationAction extends Action { } public run(): TPromise { - const activeControl = this.editorService.activeControl; - const activeCodeEditor = getEditorWidget(activeControl); + const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorControl); if (!activeCodeEditor) { return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); } + if (!isWritableCodeEditor(activeCodeEditor)) { return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]); } @@ -1097,8 +1095,7 @@ export class ChangeEOLAction extends Action { } public run(): TPromise { - let activeControl = this.editorService.activeControl; - const activeCodeEditor = getEditorWidget(activeControl); + const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorControl); if (!activeCodeEditor) { return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); } @@ -1118,8 +1115,7 @@ export class ChangeEOLAction extends Action { return this.quickOpenService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), autoFocus: { autoFocusIndex: selectedIndex } }).then(eol => { if (eol) { - activeControl = this.editorService.activeControl; - const activeCodeEditor = getEditorWidget(activeControl); + const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorControl); if (activeCodeEditor && isWritableCodeEditor(activeCodeEditor)) { const textModel = activeCodeEditor.getModel(); textModel.pushEOL(eol.eol); @@ -1146,11 +1142,11 @@ export class ChangeEncodingAction extends Action { } public run(): TPromise { - let activeControl = this.editorService.activeControl; - if (!getEditorWidget(activeControl) || !activeControl.input) { + if (!getCodeEditor(this.editorService.activeTextEditorControl)) { return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); } + let activeControl = this.editorService.activeControl; let encodingSupport: IEncodingSupport = toEditorWithEncodingSupport(activeControl.input); if (!encodingSupport) { return this.quickOpenService.pick([{ label: nls.localize('noFileEditor', "No file active at this time") }]); diff --git a/src/vs/workbench/browser/parts/editor/textEditor.ts b/src/vs/workbench/browser/parts/editor/textEditor.ts index c7b8599ee19..6fae2041eb3 100644 --- a/src/vs/workbench/browser/parts/editor/textEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textEditor.ts @@ -20,11 +20,10 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { Scope } from 'vs/workbench/common/memento'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; import { ITextFileService, SaveReason, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; -import { isDiffEditor, isCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { isDiffEditor, isCodeEditor, ICodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { INextEditorGroupsService, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService'; import { CancellationToken } from 'vs/base/common/cancellation'; import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService'; @@ -135,7 +134,7 @@ export abstract class BaseTextEditor extends BaseEditor { this.editorControl = this.createEditorControl(parent, this.computeConfiguration(this.configurationService.getValue(this.getResource()))); // Model & Language changes - const codeEditor = getCodeEditor(this); + const codeEditor = getCodeEditor(this.editorControl); if (codeEditor) { this.toUnbind.push(codeEditor.onDidChangeModelLanguage(e => this.updateEditorConfiguration())); this.toUnbind.push(codeEditor.onDidChangeModel(e => this.updateEditorConfiguration())); @@ -294,7 +293,7 @@ export abstract class BaseTextEditor extends BaseEditor { } protected getResource(): URI { - const codeEditor = getCodeEditor(this); + const codeEditor = getCodeEditor(this.editorControl); if (codeEditor) { const model = codeEditor.getModel(); if (model) { diff --git a/src/vs/workbench/browser/parts/editor2/editor2.ts b/src/vs/workbench/browser/parts/editor2/editor2.ts index 234760ff4e8..480d857fbb5 100644 --- a/src/vs/workbench/browser/parts/editor2/editor2.ts +++ b/src/vs/workbench/browser/parts/editor2/editor2.ts @@ -15,7 +15,7 @@ import { Event } from 'vs/base/common/event'; import { assign } from 'vs/base/common/objects'; import { IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration'; import { ISerializableView } from 'vs/base/browser/ui/grid/grid'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; +import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; export const EDITOR_TITLE_HEIGHT = 35; @@ -101,10 +101,10 @@ export interface INextEditorGroupView extends IDisposable, ISerializableView, IN } export function getActiveTextEditorOptions(group: INextEditorGroup, expectedActiveEditor?: IEditorInput, presetOptions?: EditorOptions): EditorOptions { - const activeGroupControl = getCodeEditor(group.activeControl); - if (activeGroupControl) { + const activeGroupCodeEditor = group.activeControl ? getCodeEditor(group.activeControl.getControl()) : void 0; + if (activeGroupCodeEditor) { if (!expectedActiveEditor || expectedActiveEditor.matches(group.activeEditor)) { - return TextEditorOptions.fromEditor(activeGroupControl, presetOptions); + return TextEditorOptions.fromEditor(activeGroupCodeEditor, presetOptions); } } diff --git a/src/vs/workbench/browser/parts/editor2/nextTitleControl.ts b/src/vs/workbench/browser/parts/editor2/nextTitleControl.ts index 3c2c8b07a94..4bad577963b 100644 --- a/src/vs/workbench/browser/parts/editor2/nextTitleControl.ts +++ b/src/vs/workbench/browser/parts/editor2/nextTitleControl.ts @@ -30,7 +30,7 @@ import { IMenuService, MenuId, IMenu, ExecuteCommandAction } from 'vs/platform/a import { ResourceContextKey } from 'vs/workbench/common/resources'; import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService'; import { Themable } from 'vs/workbench/common/theme'; -import { isDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser'; +import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { Dimension, addDisposableListener, EventType } from 'vs/base/browser/dom'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; @@ -169,8 +169,7 @@ export abstract class NextTitleControl extends Themable { // Contributed Actions this.disposeOnEditorActions = dispose(this.disposeOnEditorActions); - const widget = activeControl.getControl(); - const codeEditor = isCodeEditor(widget) && widget || isDiffEditor(widget) && widget.getModifiedEditor(); + const codeEditor = getCodeEditor(activeControl.getControl()); const scopedContextKeyService = codeEditor && codeEditor.invokeWithinContext(accessor => accessor.get(IContextKeyService)) || this.contextKeyService; const titleBarMenu = this.menuService.createMenu(MenuId.EditorTitle, scopedContextKeyService); this.disposeOnEditorActions.push(titleBarMenu, titleBarMenu.onDidChange(() => this.updateEditorActionsToolbar())); diff --git a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts index bdc14b345ac..846a70fc6a9 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts @@ -28,7 +28,7 @@ import { IResourceInput } from 'vs/platform/editor/common/editor'; import { IFileService } from 'vs/platform/files/common/files'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IEditorViewState } from 'vs/editor/common/editorCommon'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; +import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes'; import { isWindows, isMacintosh } from 'vs/base/common/platform'; @@ -97,12 +97,11 @@ function save(resource: URI, isSaveAs: boolean, editorService: INextEditorServic } let viewStateOfSource: IEditorViewState; - const activeEditor = editorService.activeControl; - const editor = getCodeEditor(activeEditor); - if (editor) { - const activeResource = toResource(activeEditor.input, { supportSideBySide: true }); + const activeCodeEditor = getCodeEditor(editorService.activeTextEditorControl); + if (activeCodeEditor) { + const activeResource = toResource(editorService.activeEditor, { supportSideBySide: true }); if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === Schemas.untitled) && activeResource.toString() === resource.toString()) { - viewStateOfSource = editor.saveViewState(); + viewStateOfSource = activeCodeEditor.saveViewState(); } } diff --git a/src/vs/workbench/services/history/electron-browser/history.ts b/src/vs/workbench/services/history/electron-browser/history.ts index 11b7690cd01..d02d6f0fe7a 100644 --- a/src/vs/workbench/services/history/electron-browser/history.ts +++ b/src/vs/workbench/services/history/electron-browser/history.ts @@ -24,7 +24,7 @@ import { once, debounceEvent } from 'vs/base/common/event'; import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration'; import { INextEditorGroupsService, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService'; import { IWindowsService } from 'vs/platform/windows/common/windows'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; +import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { getExcludes, ISearchConfiguration } from 'vs/platform/search/common/search'; import { IExpression } from 'vs/base/common/glob'; import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; @@ -185,7 +185,7 @@ export class HistoryService implements IHistoryService { this.handleActiveEditorChange(activeControl); // Apply listener for selection changes if this is a text editor - const control = getCodeEditor(activeControl); + const control = getCodeEditor(this.editorService.activeTextEditorControl); if (control) { // Debounce the event with a timeout of 0ms so that multiple calls to @@ -441,16 +441,16 @@ export class HistoryService implements IHistoryService { this.history = this.history.filter(e => !this.matches(arg1, e)); } - private handleEditorEventInStack(editor: IBaseEditor, event?: ICursorPositionChangedEvent): void { - const control = getCodeEditor(editor); + private handleEditorEventInStack(control: IBaseEditor, event?: ICursorPositionChangedEvent): void { + const codeEditor = control ? getCodeEditor(control.getControl()) : void 0; // treat editor changes that happen as part of stack navigation specially // we do not want to add a new stack entry as a matter of navigating the // stack but we need to keep our currentTextEditorState up to date with // the navigtion that occurs. if (this.navigatingInStack) { - if (control && editor.input) { - this.currentTextEditorState = new TextEditorState(editor.input, control.getSelection()); + if (codeEditor && control.input) { + this.currentTextEditorState = new TextEditorState(control.input, codeEditor.getSelection()); } else { this.currentTextEditorState = null; // we navigated to a non text editor } @@ -460,16 +460,16 @@ export class HistoryService implements IHistoryService { else { // navigation inside text editor - if (control && editor.input) { - this.handleTextEditorEvent(editor, control, event); + if (codeEditor && control.input) { + this.handleTextEditorEvent(control, codeEditor, event); } // navigation to non-text editor else { this.currentTextEditorState = null; // at this time we have no active text editor view state - if (editor && editor.input) { - this.handleNonTextEditorEvent(editor); + if (control && control.input) { + this.handleNonTextEditorEvent(control); } } } diff --git a/src/vs/workbench/services/preferences/browser/preferencesService.ts b/src/vs/workbench/services/preferences/browser/preferencesService.ts index 4509a724c37..5e21ad31293 100644 --- a/src/vs/workbench/services/preferences/browser/preferencesService.ts +++ b/src/vs/workbench/services/preferences/browser/preferencesService.ts @@ -24,7 +24,6 @@ import { SettingsEditorModel, DefaultSettingsEditorModel, DefaultKeybindingsEdit import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { DefaultPreferencesEditorInput, PreferencesEditorInput, KeybindingsEditorInput, SettingsEditor2Input } from 'vs/workbench/services/preferences/common/preferencesEditorInput'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; -import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; import { EditOperation } from 'vs/editor/common/core/editOperation'; import { Position, IPosition } from 'vs/editor/common/core/position'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; @@ -33,7 +32,7 @@ import { IJSONEditingService } from 'vs/workbench/services/configuration/common/ import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { IModeService } from 'vs/editor/common/services/modeService'; import { parse } from 'vs/base/common/json'; -import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { ICodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { assign } from 'vs/base/common/objects'; import { INextEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/nextEditorService'; @@ -237,12 +236,14 @@ export class PreferencesService extends Disposable implements IPreferencesServic configureSettingsForLanguage(language: string): void { this.openGlobalSettings() .then(editor => { - const codeEditor = getCodeEditor(editor); - this.getPosition(language, codeEditor) - .then(position => { - codeEditor.setPosition(position); - codeEditor.focus(); - }); + const codeEditor = getCodeEditor(editor.getControl()); + if (codeEditor) { + this.getPosition(language, codeEditor) + .then(position => { + codeEditor.setPosition(position); + codeEditor.focus(); + }); + } }); } -- GitLab