提交 2876e9cc 编写于 作者: B Benjamin Pasero

some fixes around usage of file editor input

上级 7e299e73
......@@ -459,7 +459,7 @@ export class EditorOptions implements IEditorOptions {
* Helper to create EditorOptions inline.
*/
public static create(settings: IEditorOptions): EditorOptions {
let options = new EditorOptions();
const options = new EditorOptions();
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
options.revealIfVisible = settings.revealIfVisible;
......@@ -537,7 +537,7 @@ export class TextEditorOptions extends EditorOptions {
}
if (input.options.selection) {
let selection = input.options.selection;
const selection = input.options.selection;
options.selection(selection.startLineNumber, selection.startColumn, selection.endLineNumber, selection.endColumn);
}
......@@ -573,7 +573,7 @@ export class TextEditorOptions extends EditorOptions {
* Helper to create TextEditorOptions inline.
*/
public static create(settings: ITextEditorOptions): TextEditorOptions {
let options = new TextEditorOptions();
const options = new TextEditorOptions();
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
options.revealIfVisible = settings.revealIfVisible;
......@@ -660,7 +660,7 @@ export class TextEditorOptions extends EditorOptions {
// Select
if (!types.isUndefinedOrNull(this.endLineNumber) && !types.isUndefinedOrNull(this.endColumn)) {
let range = {
const range = {
startLineNumber: this.startLineNumber,
startColumn: this.startColumn,
endLineNumber: this.endLineNumber,
......@@ -672,7 +672,7 @@ export class TextEditorOptions extends EditorOptions {
// Reveal
else {
let pos = {
const pos = {
lineNumber: this.startLineNumber,
column: this.startColumn
};
......@@ -705,7 +705,7 @@ export class TextDiffEditorOptions extends TextEditorOptions {
* Helper to create TextDiffEditorOptions inline.
*/
public static create(settings: ITextDiffEditorOptions): TextDiffEditorOptions {
let options = new TextDiffEditorOptions();
const options = new TextDiffEditorOptions();
options.autoRevealFirstChange = settings.autoRevealFirstChange;
......@@ -746,7 +746,7 @@ export function getUntitledOrFileResource(input: IEditorInput, supportDiff?: boo
}
// File
let fileInput = asFileEditorInput(input, supportDiff);
const fileInput = asFileEditorInput(input, supportDiff);
return fileInput && fileInput.getResource();
}
......@@ -754,7 +754,7 @@ export function getUntitledOrFileResource(input: IEditorInput, supportDiff?: boo
// TODO@Ben every editor should have an associated resource
export function getResource(input: IEditorInput): URI {
if (input instanceof EditorInput && typeof (<any>input).getResource === 'function') {
let candidate = (<any>input).getResource();
const candidate = (<any>input).getResource();
if (candidate instanceof URI) {
return candidate;
}
......@@ -795,9 +795,9 @@ export function asFileEditorInput(obj: any, supportDiff?: boolean): IFileEditorI
obj = (<BaseDiffEditorInput>obj).modifiedInput;
}
let i = <IFileEditorInput>obj;
const i = <IFileEditorInput>obj;
return i instanceof EditorInput && types.areFunctions(i.setResource, i.setEncoding, i.getEncoding, i.getResource) ? i : null;
return i instanceof EditorInput && types.areFunctions(i.setResource, i.setEncoding, i.getEncoding, i.getResource, i.setPreferredEncoding) ? i : null;
}
export interface IStacksModelChangeEvent {
......
......@@ -11,7 +11,7 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
/**
* An implementation of editor for binary files like images or videos leveraging the FileEditorInput.
* An implementation of editor for binary files like images.
*/
export class BinaryFileEditor extends BaseBinaryResourceEditor {
......
......@@ -26,7 +26,7 @@ import {dispose, IDisposable} from 'vs/base/common/lifecycle';
import {LocalFileChangeEvent, VIEWLET_ID, ITextFileService} from 'vs/workbench/parts/files/common/files';
import {IFileService, IFileStat, IImportResult} from 'vs/platform/files/common/files';
import {DiffEditorInput, toDiffLabel} from 'vs/workbench/common/editor/diffEditorInput';
import {asFileEditorInput, getUntitledOrFileResource, UntitledEditorInput, IEditorIdentifier} from 'vs/workbench/common/editor';
import {asFileEditorInput, getUntitledOrFileResource, IEditorIdentifier} from 'vs/workbench/common/editor';
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import {FileStat, NewStatPlaceholder} from 'vs/workbench/parts/files/common/explorerViewModel';
import {ExplorerView} from 'vs/workbench/parts/files/browser/views/explorerView';
......@@ -1633,8 +1633,9 @@ export class SaveAllInGroupAction extends BaseSaveAllAction {
const editorGroup = editorIdentifier.group;
const resourcesToSave = [];
editorGroup.getEditors().forEach(editor => {
if (editor instanceof FileEditorInput || editor instanceof UntitledEditorInput) {
resourcesToSave.push(editor.getResource());
const resource = getUntitledOrFileResource(editor, true);
if (resource) {
resourcesToSave.push(resource);
}
});
......
......@@ -22,9 +22,9 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {UntitledEditorInput, IEditorGroup, IEditorStacksModel} from 'vs/workbench/common/editor';
import {UntitledEditorInput, IEditorGroup, IEditorStacksModel, getUntitledOrFileResource} from 'vs/workbench/common/editor';
import {ContributableActionProvider} from 'vs/workbench/browser/actionBarRegistry';
import {ITextFileService, AutoSaveMode, FileEditorInput, asFileResource} from 'vs/workbench/parts/files/common/files';
import {ITextFileService, AutoSaveMode, asFileResource} from 'vs/workbench/parts/files/common/files';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {EditorStacksModel, EditorGroup} from 'vs/workbench/common/editor/editorStacksModel';
import {keybindingForAction, SaveFileAction, RevertFileAction, SaveFileAsAction, OpenToSideAction, SelectResourceForCompareAction, CompareResourcesAction, SaveAllInGroupAction} from 'vs/workbench/parts/files/browser/fileActions';
......@@ -64,13 +64,7 @@ export class OpenEditor {
}
public getResource(): uri {
if (this.editor instanceof FileEditorInput) {
return (<FileEditorInput>this.editor).getResource();
} else if (this.editor instanceof UntitledEditorInput) {
return (<UntitledEditorInput>this.editor).getResource();
}
return null;
return getUntitledOrFileResource(this.editor, true);
}
}
......
......@@ -26,7 +26,6 @@ import GitActions = require('vs/workbench/parts/git/browser/gitActions');
import GitModel = require('vs/workbench/parts/git/common/gitModel');
import Viewer = require('vs/workbench/parts/git/browser/views/changes/changesViewer');
import GitEditorInputs = require('vs/workbench/parts/git/browser/gitEditorInputs');
import Files = require('vs/workbench/parts/files/common/files');
import {IOutputService} from 'vs/workbench/parts/output/common/output';
import WorkbenchEditorCommon = require('vs/workbench/common/editor');
import InputBox = require('vs/base/browser/ui/inputbox/inputBox');
......@@ -450,8 +449,8 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
return (<GitEditorInputs.NativeGitIndexStringEditorInput> input).getFileStatus() || null;
}
if (input instanceof Files.FileEditorInput) {
const fileInput = <Files.FileEditorInput> input;
const fileInput = WorkbenchEditorCommon.asFileEditorInput(input);
if (fileInput) {
const resource = fileInput.getResource();
const workspaceRoot = this.contextService.getWorkspace().resource.fsPath;
......
......@@ -6,20 +6,20 @@
import * as assert from 'assert';
import { TestInstantiationService } from 'vs/test/utils/instantiationTestUtils';
import URI from 'vs/base/common/uri';
import {createMockModelService, TestEditorService, workbenchInstantiationService} from 'vs/test/utils/servicesTestUtils';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IModeService} from 'vs/editor/common/services/modeService';
import { createMockModelService, TestEditorService, workbenchInstantiationService } from 'vs/test/utils/servicesTestUtils';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import WorkbenchEditorService = require('vs/workbench/services/editor/common/editorService');
import { RangeHighlightDecorations } from 'vs/workbench/common/editor/rangeDecorations';
import {Model} from 'vs/editor/common/model/model';
import {mockCodeEditor, MockCodeEditor} from 'vs/editor/test/common/mocks/mockCodeEditor';
import { Model } from 'vs/editor/common/model/model';
import { mockCodeEditor, MockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {IEditorInput} from 'vs/platform/editor/common/editor';
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import {TextModel} from 'vs/editor/common/model/textModel';
import {Range} from 'vs/editor/common/core/range';
import {Position} from 'vs/editor/common/core/position';
import {Cursor} from 'vs/editor/common/controller/cursor';
import { IEditorInput } from 'vs/platform/editor/common/editor';
import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import { TextModel } from 'vs/editor/common/model/textModel';
import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import { Cursor } from 'vs/editor/common/controller/cursor';
suite('Editor - Range decorations', () => {
......@@ -36,8 +36,8 @@ suite('Editor - Range decorations', () => {
setup(() => {
instantiationService = <TestInstantiationService>workbenchInstantiationService();
editorService= <WorkbenchEditorService.IWorkbenchEditorService>instantiationService.stub(WorkbenchEditorService.IWorkbenchEditorService, new TestEditorService(function () { }));
modeService= instantiationService.stub(IModeService);
editorService = <WorkbenchEditorService.IWorkbenchEditorService>instantiationService.stub(WorkbenchEditorService.IWorkbenchEditorService, new TestEditorService(function () { }));
modeService = instantiationService.stub(IModeService);
modelService = <IModelService>instantiationService.stub(IModelService, createMockModelService(instantiationService));
text = 'LINE1' + '\n' + 'LINE2' + '\n' + 'LINE3' + '\n' + 'LINE4' + '\r\n' + 'LINE5';
model = aModel(URI.file('some_file'));
......@@ -65,7 +65,7 @@ suite('Editor - Range decorations', () => {
});
test('remove highlight range', function () {
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 }});
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
testObject.removeHighlightRange();
let actuals = rangeHighlightDecorations(model);
......@@ -74,7 +74,7 @@ suite('Editor - Range decorations', () => {
});
test('highlight range for the resource removes previous highlight', function () {
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 }});
testObject.highlightRange({ resource: model.uri, range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 } });
let range: editorCommon.IRange = { startLineNumber: 2, startColumn: 2, endLineNumber: 4, endColumn: 3 };
testObject.highlightRange({ resource: model.uri, range });
......@@ -124,7 +124,7 @@ suite('Editor - Range decorations', () => {
test('previous highlight is not removed if not active editor', function () {
let range: editorCommon.IRange = { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 };
testObject.highlightRange({ resource: model.uri, range});
testObject.highlightRange({ resource: model.uri, range });
let model1 = aModel(URI.file('some model'));
testObject.highlightRange({ resource: model1.uri, range: { startLineNumber: 2, startColumn: 1, endLineNumber: 2, endColumn: 1 } });
......@@ -150,7 +150,7 @@ suite('Editor - Range decorations', () => {
function mockEditorService(resource: URI)
function mockEditorService(arg: any) {
let editorInput: IEditorInput = arg instanceof URI ? instantiationService.createInstance(FileEditorInput, arg, void 0) : arg;
instantiationService.stub(WorkbenchEditorService.IWorkbenchEditorService, 'getActiveEditorInput', editorInput);
instantiationService.stub(WorkbenchEditorService.IWorkbenchEditorService, 'getActiveEditorInput', editorInput);
}
function rangeHighlightDecorations(m: Model): editorCommon.IRange[] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册