mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Save edit data scroll position when switching tabs (#2129)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user