From 4bfa6b3a5d290049ebbbf3e2c269ac46fc9ef200 Mon Sep 17 00:00:00 2001 From: Matt Irvine Date: Fri, 20 Jul 2018 07:48:12 -0700 Subject: [PATCH] Save editor cursor/scroll position when switching sql files (#1978) * Save editor layouts when switching sql files * Move import * Restore the view state after laying out the editor --- src/sql/parts/query/editor/queryEditor.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sql/parts/query/editor/queryEditor.ts b/src/sql/parts/query/editor/queryEditor.ts index 29c47890f4..8db8df87eb 100644 --- a/src/sql/parts/query/editor/queryEditor.ts +++ b/src/sql/parts/query/editor/queryEditor.ts @@ -10,7 +10,7 @@ import * as DOM from 'vs/base/browser/dom'; import { EditorInput, EditorOptions } from 'vs/workbench/common/editor'; import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; -import { IEditorControl, Position, IEditor } from 'vs/platform/editor/common/editor'; +import { IEditorControl, Position, IEditor, IEditorInput } from 'vs/platform/editor/common/editor'; import { VerticalFlexibleSash, HorizontalFlexibleSash, IFlexibleSash } from 'sql/parts/query/views/flexibleSash'; import { Orientation } from 'vs/base/browser/ui/sash/sash'; @@ -31,6 +31,7 @@ import { IEditorGroupService } from 'vs/workbench/services/group/common/groupSer import { CodeEditor } from 'vs/editor/browser/codeEditor'; import { IDisposable } from 'vs/base/common/lifecycle'; import { IRange } from 'vs/editor/common/core/range'; +import { IEditorViewState } from 'vs/editor/common/editorCommon'; import { QueryResultsInput } from 'sql/parts/query/common/queryResultsInput'; import { QueryInput } from 'sql/parts/query/common/queryInput'; @@ -87,6 +88,8 @@ export class QueryEditor extends BaseEditor { private _estimatedQueryPlanAction: EstimatedQueryPlanAction; private _actualQueryPlanAction: ActualQueryPlanAction; + private _savedViewStates = new Map(); + constructor( @ITelemetryService _telemetryService: ITelemetryService, @IThemeService themeService: IThemeService, @@ -481,6 +484,8 @@ export class QueryEditor extends BaseEditor { private _updateInput(oldInput: QueryInput, newInput: QueryInput, options?: EditorOptions): TPromise { if (this._sqlEditor) { + let sqlEditorViewState = this._sqlEditor.getControl().saveViewState(); + this._savedViewStates.set(this._sqlEditor.input, sqlEditorViewState); this._sqlEditor.clearInput(); } @@ -557,7 +562,12 @@ export class QueryEditor extends BaseEditor { // Run all three steps synchronously return createEditors() .then(onEditorsCreated) - .then(doLayout); + .then(doLayout) + .then(() => { + if (this._savedViewStates.has(newInput.sql)) { + this._sqlEditor.getControl().restoreViewState(this._savedViewStates.get(newInput.sql)); + } + }); } /**