Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Folding won't be remembered after latest update. (fixes #26157) #26322

Merged
merged 1 commit into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/editor/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class BaseTextEditor extends BaseEditor {
@IWorkbenchThemeService protected themeService: IWorkbenchThemeService,
@IModeService private modeService: IModeService,
@ITextFileService private textFileService: ITextFileService,
@IEditorGroupService private editorGroupService: IEditorGroupService
@IEditorGroupService protected editorGroupService: IEditorGroupService
) {
super(id, telemetryService, themeService);

Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ export interface IStacksModelChangeEvent {
export interface IEditorStacksModel {

onModelChanged: Event<IStacksModelChangeEvent>;

onWillCloseEditor: Event<IEditorIdentifier>;
onEditorClosed: Event<IGroupEvent>;

groups: IEditorGroup[];
Expand Down
9 changes: 8 additions & 1 deletion src/vs/workbench/common/editor/editorStacksModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ export class EditorStacksModel implements IEditorStacksModel {
private _onEditorDirty: Emitter<EditorIdentifier>;
private _onEditorLabelChange: Emitter<EditorIdentifier>;
private _onEditorOpened: Emitter<EditorIdentifier>;
private _onWillCloseEditor: Emitter<EditorIdentifier>;
private _onEditorClosed: Emitter<GroupEvent>;
private _onModelChanged: Emitter<IStacksModelChangeEvent>;

Expand All @@ -728,9 +729,10 @@ export class EditorStacksModel implements IEditorStacksModel {
this._onEditorDirty = new Emitter<EditorIdentifier>();
this._onEditorLabelChange = new Emitter<EditorIdentifier>();
this._onEditorOpened = new Emitter<EditorIdentifier>();
this._onWillCloseEditor = new Emitter<EditorIdentifier>();
this._onEditorClosed = new Emitter<GroupEvent>();

this.toDispose.push(this._onGroupOpened, this._onGroupClosed, this._onGroupActivated, this._onGroupDeactivated, this._onGroupMoved, this._onGroupRenamed, this._onModelChanged, this._onEditorDisposed, this._onEditorDirty, this._onEditorLabelChange, this._onEditorClosed);
this.toDispose.push(this._onGroupOpened, this._onGroupClosed, this._onGroupActivated, this._onGroupDeactivated, this._onGroupMoved, this._onGroupRenamed, this._onModelChanged, this._onEditorDisposed, this._onEditorDirty, this._onEditorLabelChange, this._onEditorClosed, this._onWillCloseEditor);

this.registerListeners();
}
Expand Down Expand Up @@ -783,6 +785,10 @@ export class EditorStacksModel implements IEditorStacksModel {
return this._onEditorOpened.event;
}

public get onWillCloseEditor(): Event<EditorIdentifier> {
return this._onWillCloseEditor.event;
}

public get onEditorClosed(): Event<GroupEvent> {
return this._onEditorClosed.event;
}
Expand Down Expand Up @@ -1155,6 +1161,7 @@ export class EditorStacksModel implements IEditorStacksModel {
unbind.push(group.onEditorStateChanged(editor => this._onModelChanged.fire({ group, editor })));
unbind.push(group.onEditorOpened(editor => this._onEditorOpened.fire({ editor, group })));
unbind.push(group.onEditorClosed(event => {
this._onWillCloseEditor.fire({ editor: event.editor, group });
this.handleOnEditorClosed(event);
this._onEditorClosed.fire(event);
}));
Expand Down
29 changes: 19 additions & 10 deletions src/vs/workbench/parts/files/browser/editors/textFileEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Action } from 'vs/base/common/actions';
import { VIEWLET_ID, TEXT_FILE_EDITOR_ID } from 'vs/workbench/parts/files/common/files';
import { ITextFileEditorModel, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import { EditorOptions, TextEditorOptions } from 'vs/workbench/common/editor';
import { EditorOptions, TextEditorOptions, IEditorIdentifier } from 'vs/workbench/common/editor';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import { ExplorerViewlet } from 'vs/workbench/parts/files/browser/explorerViewlet';
Expand Down Expand Up @@ -58,6 +58,9 @@ export class TextFileEditor extends BaseTextEditor {

// Clear view state for deleted files
this.toUnbind.push(this.fileService.onFileChanges(e => this.onFilesChanged(e)));

// React to editors closing to preserve view state
this.toUnbind.push(editorGroupService.getStacksModel().onWillCloseEditor(e => this.onWillCloseEditor(e)));
}

private onFilesChanged(e: FileChangesEvent): void {
Expand All @@ -67,6 +70,12 @@ export class TextFileEditor extends BaseTextEditor {
}
}

private onWillCloseEditor(e: IEditorIdentifier): void {
if (e.editor === this.input && this.position === this.editorGroupService.getStacksModel().positionOfGroup(e.group)) {
this.doSaveTextEditorViewState(this.input);
}
}

public getTitle(): string {
return this.input ? this.input.getName() : nls.localize('textFileEditor', "Text File Editor");
}
Expand Down Expand Up @@ -104,9 +113,7 @@ export class TextFileEditor extends BaseTextEditor {
}

// Remember view settings if input changes
if (oldInput) {
this.saveTextEditorViewState(oldInput.getResource().toString());
}
this.doSaveTextEditorViewState(oldInput);

// Different Input (Reload)
return input.resolve(true).then(resolvedModel => {
Expand Down Expand Up @@ -224,9 +231,7 @@ export class TextFileEditor extends BaseTextEditor {
public clearInput(): void {

// Keep editor view state in settings to restore when coming back
if (this.input) {
this.saveTextEditorViewState(this.input.getResource().toString());
}
this.doSaveTextEditorViewState(this.input);

// Clear Model
this.getControl().setModel(null);
Expand All @@ -238,11 +243,15 @@ export class TextFileEditor extends BaseTextEditor {
public shutdown(): void {

// Save View State
if (this.input) {
this.saveTextEditorViewState(this.input.getResource().toString());
}
this.doSaveTextEditorViewState(this.input);

// Call Super
super.shutdown();
}

private doSaveTextEditorViewState(input: FileEditorInput): void {
if (input && !input.isDisposed()) {
this.saveTextEditorViewState(input.getResource().toString());
}
}
}
38 changes: 36 additions & 2 deletions src/vs/workbench/test/browser/editorStacksModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as assert from 'assert';
import { EditorStacksModel, EditorGroup, GroupEvent } from 'vs/workbench/common/editor/editorStacksModel';
import { EditorInput, IFileEditorInput, IEditorIdentifier, IEditorGroup, IStacksModelChangeEvent, IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory } from 'vs/workbench/common/editor';
import { EditorInput, IFileEditorInput, IEditorIdentifier, IEditorGroup, IStacksModelChangeEvent, IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory, IGroupEvent } from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
import { TestStorageService, TestLifecycleService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
Expand Down Expand Up @@ -47,6 +47,8 @@ interface ModelEvents {
renamed: IEditorGroup[];
disposed: IEditorIdentifier[];
changed: IStacksModelChangeEvent[];
editorClosed: IGroupEvent[];
editorWillClose: IEditorIdentifier[];
}

interface GroupEvents {
Expand All @@ -66,7 +68,9 @@ function modelListener(model: EditorStacksModel): ModelEvents {
moved: [],
renamed: [],
disposed: [],
changed: []
changed: [],
editorClosed: [],
editorWillClose: []
};

model.onGroupOpened(g => modelEvents.opened.push(g));
Expand All @@ -76,6 +80,8 @@ function modelListener(model: EditorStacksModel): ModelEvents {
model.onGroupRenamed(g => modelEvents.renamed.push(g));
model.onEditorDisposed(e => modelEvents.disposed.push(e));
model.onModelChanged(e => modelEvents.changed.push(e));
model.onWillCloseEditor(e => modelEvents.editorWillClose.push(e));
model.onEditorClosed(e => modelEvents.editorClosed.push(e));

return modelEvents;
}
Expand Down Expand Up @@ -1671,6 +1677,7 @@ suite('Editor Stacks Model', () => {

test('Stack - Multiple Editors - Editor Disposed on Close', function () {
const model = create();
const events = modelListener(model);

const group1 = model.openGroup('group1');
const group2 = model.openGroup('group2');
Expand All @@ -1687,6 +1694,13 @@ suite('Editor Stacks Model', () => {

group1.closeEditor(input3);

assert.equal(events.editorClosed.length, 1);
assert.equal(events.editorClosed[0].editor, input3);

assert.equal(events.editorWillClose.length, 1);
assert.equal(events.editorWillClose[0].editor, input3);
assert.equal(events.editorWillClose[0].group, group1);

assert.equal(input3.isDisposed(), true);

group2.openEditor(input2, { pinned: true, active: true });
Expand All @@ -1695,18 +1709,38 @@ suite('Editor Stacks Model', () => {

group1.closeEditor(input2);

assert.equal(events.editorClosed.length, 2);
assert.equal(events.editorClosed[1].editor, input2);

assert.equal(events.editorWillClose.length, 2);
assert.equal(events.editorWillClose[1].editor, input2);
assert.equal(events.editorWillClose[1].group, group1);

assert.equal(input2.isDisposed(), false);

group2.closeEditor(input2);

assert.equal(events.editorClosed.length, 3);
assert.equal(events.editorClosed[2].editor, input2);

assert.equal(events.editorWillClose.length, 3);
assert.equal(events.editorWillClose[2].editor, input2);
assert.equal(events.editorWillClose[2].group, group2);

assert.equal(input2.isDisposed(), true);

group1.closeAllEditors();

assert.equal(events.editorClosed.length, 5);
assert.equal(events.editorWillClose.length, 5);

assert.equal(input4.isDisposed(), false);

model.closeGroups();

assert.equal(events.editorClosed.length, 7);
assert.equal(events.editorWillClose.length, 7);

assert.equal(input4.isDisposed(), true);
});

Expand Down