提交 82d9feb3 编写于 作者: B Benjamin Pasero

better fix for #8202

上级 be2143dd
......@@ -251,23 +251,19 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
if (!this.cursor || !this.hasView) {
return;
}
if (state) {
var codeEditorState = <editorCommon.ICodeEditorViewState>state;
var cursorState = codeEditorState.cursorState;
if (cursorState) {
if (Array.isArray(cursorState)) {
this.cursor.restoreState(<editorCommon.ICursorState[]>cursorState);
} else {
// Backwards compatibility
this.cursor.restoreState([<editorCommon.ICursorState>cursorState]);
}
}
if (codeEditorState.viewState) {
this._view.restoreState(codeEditorState.viewState);
var s = <any>state;
if (s && s.cursorState && s.viewState) {
var codeEditorState = <editorCommon.ICodeEditorViewState>s;
var cursorState = <any>codeEditorState.cursorState;
if (Array.isArray(cursorState)) {
this.cursor.restoreState(<editorCommon.ICursorState[]>cursorState);
} else {
// Backwards compatibility
this.cursor.restoreState([<editorCommon.ICursorState>cursorState]);
}
this._view.restoreState(codeEditorState.viewState);
let contributionsState = codeEditorState.contributionsState || {};
let contributionsState = s.contributionsState || {};
let keys = Object.keys(this._contributions);
for (let i = 0, len = keys.length; i < len; i++) {
let id = keys[i];
......
......@@ -2965,10 +2965,7 @@ export interface IViewState {
export interface ICodeEditorViewState extends IEditorViewState {
cursorState: ICursorState[];
viewState: IViewState;
contributionsState: IContributionsViewState;
}
export interface IContributionsViewState {
[id: string]: any;
contributionsState: { [id: string]: any };
}
/**
......
......@@ -2665,11 +2665,9 @@ declare module monaco.editor {
export interface ICodeEditorViewState extends IEditorViewState {
cursorState: ICursorState[];
viewState: IViewState;
contributionsState: IContributionsViewState;
}
export interface IContributionsViewState {
[id: string]: any;
contributionsState: {
[id: string]: any;
};
}
/**
......
......@@ -8,7 +8,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import Event, { Emitter } from 'vs/base/common/event';
import types = require('vs/base/common/types');
import URI from 'vs/base/common/uri';
import { IEditor, ICommonCodeEditor, IEditorViewState, IEditorOptions as ICodeEditorOptions, ICodeEditorViewState, IContributionsViewState, EditorType } from 'vs/editor/common/editorCommon';
import { IEditor, ICommonCodeEditor, IEditorViewState, IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/editorCommon';
import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IResourceInput, Position } from 'vs/platform/editor/common/editor';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
......@@ -614,7 +614,7 @@ export class TextEditorOptions extends EditorOptions {
*
* @return if something was applied
*/
public apply(editor: IEditor, extraContributionsViewState?: IContributionsViewState): boolean {
public apply(editor: IEditor): boolean {
// Editor options
if (this.editorOptions) {
......@@ -622,10 +622,10 @@ export class TextEditorOptions extends EditorOptions {
}
// View state
return this.applyViewState(editor, extraContributionsViewState);
return this.applyViewState(editor);
}
private applyViewState(editor: IEditor, extraContributionsViewState?: IContributionsViewState): boolean {
private applyViewState(editor: IEditor): boolean {
let gotApplied = false;
// First try viewstate
......@@ -637,11 +637,6 @@ export class TextEditorOptions extends EditorOptions {
// Otherwise check for selection
else if (!types.isUndefinedOrNull(this.startLineNumber) && !types.isUndefinedOrNull(this.startColumn)) {
// Additional Contributions View State only applies if we did not have view state otherwise
if (extraContributionsViewState && editor.getEditorType() === EditorType.ICodeEditor) {
editor.restoreViewState({ contributionsState: extraContributionsViewState } as ICodeEditorViewState);
}
// Select
if (!types.isUndefinedOrNull(this.endLineNumber) && !types.isUndefinedOrNull(this.endColumn)) {
const range = {
......
......@@ -10,7 +10,7 @@ import errors = require('vs/base/common/errors');
import { toErrorMessage } from 'vs/base/common/errorMessage';
import types = require('vs/base/common/types');
import paths = require('vs/base/common/paths');
import { ICodeEditorViewState } from 'vs/editor/common/editorCommon';
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';
......@@ -37,9 +37,9 @@ import { IThemeService } from 'vs/workbench/services/themes/common/themeService'
const TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'textEditorViewState';
interface ITextEditorViewState {
0?: ICodeEditorViewState;
1?: ICodeEditorViewState;
2?: ICodeEditorViewState;
0?: IEditorViewState;
1?: IEditorViewState;
2?: IEditorViewState;
}
/**
......@@ -84,7 +84,7 @@ export class TextFileEditor extends BaseTextEditor {
return <FileEditorInput>super.getInput();
}
public setInput(input: FileEditorInput, options: TextEditorOptions): TPromise<void> {
public setInput(input: FileEditorInput, options: EditorOptions): TPromise<void> {
const oldInput = this.getInput();
super.setInput(input, options);
......@@ -105,8 +105,8 @@ export class TextFileEditor extends BaseTextEditor {
if (!forceOpen && input.matches(oldInput)) {
// TextOptions (avoiding instanceof here for a reason, do not change!)
if (options && types.isFunction(options.apply)) {
options.apply(this.getControl());
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
(<TextEditorOptions>options).apply(this.getControl());
}
return TPromise.as<void>(null);
......@@ -145,17 +145,15 @@ export class TextFileEditor extends BaseTextEditor {
const textEditor = this.getControl();
textEditor.setModel(textFileModel.textEditorModel);
const previousEditorViewState = this.loadTextEditorViewState(this.storageService, this.getInput().getResource().toString());
// TextOptions (avoiding instanceof here for a reason, do not change!)
let optionsGotApplied = false;
if (options && types.isFunction(options.apply)) {
optionsGotApplied = options.apply(textEditor, previousEditorViewState && previousEditorViewState.contributionsState);
// Always restore View State if any associated
const editorViewState = this.loadTextEditorViewState(this.storageService, this.getInput().getResource().toString());
if (editorViewState) {
textEditor.restoreViewState(editorViewState);
}
// Otherwise restore previous View State if available
if (!optionsGotApplied && previousEditorViewState) {
textEditor.restoreViewState(previousEditorViewState);
// TextOptions (avoiding instanceof here for a reason, do not change!)
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
(<TextEditorOptions>options).apply(textEditor);
}
}, (error) => {
......@@ -266,7 +264,7 @@ export class TextFileEditor extends BaseTextEditor {
/**
* Loads the text editor view state for the given key and returns it.
*/
private loadTextEditorViewState(storageService: IStorageService, key: string): ICodeEditorViewState {
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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册