Save edit data scroll position when switching tabs (#2129)

This commit is contained in:
Matt Irvine
2018-08-03 16:18:18 -07:00
committed by GitHub
parent df804d0729
commit 424eb90dd8
12 changed files with 157 additions and 39 deletions

View File

@@ -11,6 +11,7 @@ import URI from 'vs/base/common/uri';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
import { EditorInput, EditorModel, ConfirmResult, EncodingMode, IEncodingSupport } from 'vs/workbench/common/editor';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorViewState } from 'vs/editor/common/editorCommon';
import { IConnectionManagementService, IConnectableInput, INewConnectionParams, RunQueryOnConnectionMode } from 'sql/parts/connection/common/connectionManagement';
import { QueryResultsInput } from 'sql/parts/query/common/queryResultsInput';
@@ -56,6 +57,8 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
private _toDispose: IDisposable[];
private _currentEventCallbacks: IDisposable[];
public savedViewState: IEditorViewState;
constructor(
private _description: string,
private _sql: UntitledEditorInput,

View File

@@ -8,6 +8,7 @@
import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { EditorInput } from 'vs/workbench/common/editor';
import { Emitter } from 'vs/base/common/event';
/**
* Input for the QueryResultsEditor. This input helps with logic for the viewing and editing of
@@ -25,6 +26,9 @@ export class QueryResultsInput extends EditorInput {
private _editorContainer: HTMLElement;
public css: HTMLStyleElement;
public readonly onRestoreViewStateEmitter = new Emitter<void>();
public readonly onSaveViewStateEmitter = new Emitter<void>();
constructor(private _uri: string) {
super();
this._visible = false;

View File

@@ -89,9 +89,6 @@ export class QueryEditor extends BaseEditor {
private _estimatedQueryPlanAction: EstimatedQueryPlanAction;
private _actualQueryPlanAction: ActualQueryPlanAction;
private _savedViewStates = new Map<IEditorInput, IEditorViewState>();
private _resultViewStateChangeEmitters = new Map<QueryResultsInput, { onSaveViewState: Emitter<void>; onRestoreViewState: Emitter<void> }>();
constructor(
@ITelemetryService _telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@@ -111,6 +108,14 @@ export class QueryEditor extends BaseEditor {
if (contextKeyService) {
this.queryEditorVisible = queryContext.QueryEditorVisibleContext.bindTo(contextKeyService);
}
if (_editorGroupService) {
_editorGroupService.onEditorOpening(e => {
if (this.isVisible() && (e.input !== this.input || e.position !== this.position)) {
this.saveEditorViewState();
}
});
}
}
// PROPERTIES //////////////////////////////////////////////////////////
@@ -500,19 +505,11 @@ export class QueryEditor extends BaseEditor {
* Handles setting input for this editor.
*/
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();
}
if (oldInput) {
let resultViewStateChangeEmitters = this._resultViewStateChangeEmitters.get(oldInput.results);
if (resultViewStateChangeEmitters) {
resultViewStateChangeEmitters.onSaveViewState.fire();
}
this._disposeEditors();
}
@@ -587,11 +584,11 @@ export class QueryEditor extends BaseEditor {
.then(onEditorsCreated)
.then(doLayout)
.then(() => {
if (this._resultViewStateChangeEmitters.has(newInput.results)) {
this._resultViewStateChangeEmitters.get(newInput.results).onRestoreViewState.fire();
if (newInput.results) {
newInput.results.onRestoreViewStateEmitter.fire();
}
if (this._savedViewStates.has(newInput.sql)) {
this._sqlEditor.getControl().restoreViewState(this._savedViewStates.get(newInput.sql));
if (newInput.savedViewState) {
this._sqlEditor.getControl().restoreViewState(newInput.savedViewState);
}
});
}
@@ -624,14 +621,6 @@ export class QueryEditor extends BaseEditor {
*/
private _onResultsEditorCreated(resultsEditor: QueryResultsEditor, resultsInput: QueryResultsInput, options: EditorOptions): TPromise<void> {
this._resultsEditor = resultsEditor;
if (!this._resultViewStateChangeEmitters.has(resultsInput)) {
this._resultViewStateChangeEmitters.set(resultsInput, {
onRestoreViewState: new Emitter<void>(),
onSaveViewState: new Emitter<void>()
});
}
let emitters = this._resultViewStateChangeEmitters.get(resultsInput);
this._resultsEditor.setViewStateChangeEvents(emitters.onRestoreViewState.event, emitters.onSaveViewState.event);
return this._resultsEditor.setInput(resultsInput, options);
}
@@ -891,6 +880,18 @@ export class QueryEditor extends BaseEditor {
editor.focus();
}
private saveEditorViewState(): void {
let queryInput = this.input as QueryInput;
if (queryInput) {
if (this._sqlEditor) {
queryInput.savedViewState = this._sqlEditor.getControl().saveViewState();
}
if (queryInput.results) {
queryInput.results.onSaveViewStateEmitter.fire();
}
}
}
// TESTING PROPERTIES ////////////////////////////////////////////////////////////
public get resultsEditor(): QueryResultsEditor {

View File

@@ -96,8 +96,6 @@ export class QueryResultsEditor extends BaseEditor {
public static AngularSelectorString: string = 'slickgrid-container.slickgridContainer';
protected _rawOptions: BareResultsGridInfo;
protected _input: QueryResultsInput;
private _restoreViewStateEvent: Event<void>;
private _saveViewStateEvent: Event<void>;
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@@ -152,11 +150,6 @@ export class QueryResultsEditor extends BaseEditor {
return TPromise.wrap<void>(null);
}
public setViewStateChangeEvents(onRestoreViewStateEvent: Event<void>, onSaveViewStateEvent: Event<void>) {
this._restoreViewStateEvent = onRestoreViewStateEvent;
this._saveViewStateEvent = onSaveViewStateEvent;
}
/**
* Load the angular components and record for this input that we have done so
*/
@@ -179,8 +172,8 @@ export class QueryResultsEditor extends BaseEditor {
// to events from the backing data service
let params: IQueryComponentParams = {
dataService: dataService,
onSaveViewState: this._saveViewStateEvent,
onRestoreViewState: this._restoreViewStateEvent
onSaveViewState: this.input.onSaveViewStateEmitter.event,
onRestoreViewState: this.input.onRestoreViewStateEmitter.event
};
bootstrapAngular(this._instantiationService,
QueryOutputModule,