提交 03871624 编写于 作者: B Benjamin Pasero

Store editor view settings per group and not per file (fixes #7206)

上级 d9491c04
......@@ -9,9 +9,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {Dimension, Builder} from 'vs/base/browser/builder';
import objects = require('vs/base/common/objects');
import {CodeEditorWidget} from 'vs/editor/browser/widget/codeEditorWidget';
import {IEditorViewState} from 'vs/editor/common/editorCommon';
import {OptionsChangeEvent, EventType as WorkbenchEventType} from 'vs/workbench/common/events';
import {Scope} from 'vs/workbench/common/memento';
import {EditorInput, EditorOptions} from 'vs/workbench/common/editor';
import {BaseEditor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {EditorConfiguration} from 'vs/editor/common/config/commonEditorConfig';
......@@ -30,8 +28,6 @@ import {IModeService} from 'vs/editor/common/services/modeService';
import {IThemeService} from 'vs/workbench/services/themes/common/themeService';
import {Selection} from 'vs/editor/common/core/selection';
const EDITOR_VIEW_STATE_PREFERENCE_KEY = 'editorViewState';
/**
* The base class of editors that leverage the text editor for the editing experience. This class is only intended to
* be subclassed and not instantiated.
......@@ -181,46 +177,6 @@ export abstract class BaseTextEditor extends BaseEditor {
return this.editorControl.getSelection();
}
/**
* Saves the text editor view state under the given key.
*/
public saveTextEditorViewState(storageService: IStorageService, key: string): void {
let editorViewState = this.editorControl.saveViewState();
const memento = this.getMemento(storageService, Scope.WORKSPACE);
let editorViewStateMemento = memento[EDITOR_VIEW_STATE_PREFERENCE_KEY];
if (!editorViewStateMemento) {
editorViewStateMemento = {};
memento[EDITOR_VIEW_STATE_PREFERENCE_KEY] = editorViewStateMemento;
}
editorViewStateMemento[key] = editorViewState;
}
/**
* Clears the text editor view state under the given key.
*/
public clearTextEditorViewState(storageService: IStorageService, keys: string[]): void {
const memento = this.getMemento(storageService, Scope.WORKSPACE);
let editorViewStateMemento = memento[EDITOR_VIEW_STATE_PREFERENCE_KEY];
if (editorViewStateMemento) {
keys.forEach((key) => delete editorViewStateMemento[key]);
}
}
/**
* Loads the text editor view state for the given key and returns it.
*/
public loadTextEditorViewState(storageService: IStorageService, key: string): IEditorViewState {
const memento = this.getMemento(storageService, Scope.WORKSPACE);
let editorViewStateMemento = memento[EDITOR_VIEW_STATE_PREFERENCE_KEY];
if (editorViewStateMemento) {
return editorViewStateMemento[key];
}
return null;
}
public dispose(): void {
// Destroy Editor Control
......
......@@ -11,7 +11,9 @@ import {MIME_BINARY, MIME_TEXT} from 'vs/base/common/mime';
import labels = require('vs/base/common/labels');
import types = require('vs/base/common/types');
import paths = require('vs/base/common/paths');
import {IEditorViewState} from 'vs/editor/common/editorCommon';
import {Action} from 'vs/base/common/actions';
import {Scope} from 'vs/workbench/common/memento';
import {IEditorOptions} from 'vs/editor/common/editorCommon';
import {VIEWLET_ID, TEXT_FILE_EDITOR_ID} from 'vs/workbench/parts/files/common/files';
import {SaveErrorHandler} from 'vs/workbench/parts/files/browser/saveErrorHandler';
......@@ -35,6 +37,15 @@ import {IModeService} from 'vs/editor/common/services/modeService';
import {IThemeService} from 'vs/workbench/services/themes/common/themeService';
import {IHistoryService} from 'vs/workbench/services/history/common/history';
const LEGACY_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'editorViewState'; // TODO@Ben migration
const TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'textEditorViewState';
interface ITextEditorViewState {
0?: IEditorViewState;
1?: IEditorViewState;
2?: IEditorViewState;
}
/**
* An implementation of editor for file system resources.
*/
......@@ -265,6 +276,63 @@ export class TextFileEditor extends BaseTextEditor {
return true; // yes, we can!
}
/**
* Saves the text editor view state under the given key.
*/
private saveTextEditorViewState(storageService: IStorageService, key: string): void {
const memento = this.getMemento(storageService, Scope.WORKSPACE);
let textEditorViewStateMemento = memento[TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY];
if (!textEditorViewStateMemento) {
textEditorViewStateMemento = Object.create(null);
memento[TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY] = textEditorViewStateMemento;
}
const editorViewState = this.getControl().saveViewState();
let fileViewState: ITextEditorViewState = textEditorViewStateMemento[key];
if (!fileViewState) {
fileViewState = Object.create(null);
textEditorViewStateMemento[key] = fileViewState;
}
if (typeof this.position === 'number') {
fileViewState[this.position] = editorViewState;
}
}
/**
* Clears the text editor view state under the given key.
*/
private clearTextEditorViewState(storageService: IStorageService, keys: string[]): void {
const memento = this.getMemento(storageService, Scope.WORKSPACE);
const textEditorViewStateMemento = memento[TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY];
if (textEditorViewStateMemento) {
keys.forEach(key => delete textEditorViewStateMemento[key]);
}
}
/**
* Loads the text editor view state for the given key and returns it.
*/
private loadTextEditorViewState(storageService: IStorageService, key: string): IEditorViewState {
const memento = this.getMemento(storageService, Scope.WORKSPACE);
const textEditorViewStateMemento = memento[TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY];
if (textEditorViewStateMemento) {
const fileViewState: ITextEditorViewState = textEditorViewStateMemento[key];
if (fileViewState) {
return fileViewState[this.position];
}
}
// TODO@Ben migration
const legacyEditorViewStateMemento = memento[LEGACY_EDITOR_VIEW_STATE_PREFERENCE_KEY];
if (legacyEditorViewStateMemento) {
return legacyEditorViewStateMemento[key];
}
return null;
}
public clearInput(): void {
// Keep editor view state in settings to restore when coming back
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册