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
This commit is contained in:
Matt Irvine
2018-07-20 07:48:12 -07:00
committed by Karl Burtram
parent d20f24be18
commit 4bfa6b3a5d

View File

@@ -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<IEditorInput, IEditorViewState>();
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<void> {
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));
}
});
}
/**