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

better fix for #8202

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