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

simplify diffEditorInput

上级 5ef42ec5
......@@ -93,12 +93,12 @@ export class TextDiffEditor extends BaseTextEditor {
if (input && options && activeDiffInput) {
// Input matches modified side of the diff editor: perform the action on modified side
if (input.matches(activeDiffInput.getModifiedInput())) {
if (input.matches(activeDiffInput.modifiedInput)) {
return this.setInput(this.getInput(), options).then(() => true);
}
// Input matches original side of the diff editor: perform the action on original side
else if (input.matches(activeDiffInput.getOriginalInput())) {
else if (input.matches(activeDiffInput.originalInput)) {
let originalEditor = this.getControl().getOriginalEditor();
if (options instanceof TextEditorOptions) {
(<TextEditorOptions>options).apply(originalEditor);
......@@ -213,8 +213,8 @@ export class TextDiffEditor extends BaseTextEditor {
let options: IDiffEditorOptions = super.getCodeEditorOptions();
let input = this.input;
if (input && types.isFunction((<DiffEditorInput>input).getModifiedInput)) {
let modifiedInput = (<DiffEditorInput>input).getModifiedInput();
if (input instanceof DiffEditorInput) {
let modifiedInput = input.modifiedInput;
let readOnly = modifiedInput instanceof StringEditorInput || modifiedInput instanceof ResourceEditorInput;
options.readOnly = readOnly;
......
......@@ -244,14 +244,6 @@ export abstract class BaseDiffEditorInput extends EditorInput {
return this._modifiedInput;
}
public getOriginalInput(): EditorInput {
return this.originalInput;
}
public getModifiedInput(): EditorInput {
return this.modifiedInput;
}
public isDirty(): boolean {
return this._modifiedInput.isDirty();
}
......@@ -568,8 +560,8 @@ export function asFileEditorInput(obj: any, supportDiff?: boolean): IFileEditorI
}
// Check for diff if we are asked to
if (supportDiff && types.isFunction((<BaseDiffEditorInput>obj).getModifiedInput)) {
obj = (<BaseDiffEditorInput>obj).getModifiedInput();
if (supportDiff && obj instanceof BaseDiffEditorInput) {
obj = (<BaseDiffEditorInput>obj).modifiedInput;
}
let i = <IFileEditorInput>obj;
......
......@@ -1140,7 +1140,7 @@ export class EditorStacksModel implements IEditorStacksModel {
// Also take care of diff editor inputs that wrap around 2 editors
if (editor instanceof DiffEditorInput) {
[editor.getOriginalInput(), editor.getModifiedInput()].forEach(editor => {
[editor.originalInput, editor.modifiedInput].forEach(editor => {
if (!this.isOpen(editor)) {
editor.close();
}
......
......@@ -248,7 +248,7 @@ export class FileTracker implements IWorkbenchContribution {
// Support diff editor input too
if (input instanceof DiffEditorInput) {
input = (<DiffEditorInput>input).getModifiedInput();
input = (<DiffEditorInput>input).modifiedInput;
}
return input instanceof FileEditorInput && (<FileEditorInput>input).getResource().toString() === resource.toString();
......@@ -261,7 +261,7 @@ export class FileTracker implements IWorkbenchContribution {
let group = stacks.groupAt(editor.position);
let input = editor.input;
if (input instanceof DiffEditorInput) {
input = (<DiffEditorInput>input).getModifiedInput();
input = (<DiffEditorInput>input).modifiedInput;
}
let inputResource: URI;
......@@ -322,15 +322,14 @@ export class FileTracker implements IWorkbenchContribution {
private getMatchingFileEditorInputFromDiff(input: DiffEditorInput, arg: any): FileEditorInput {
// First try modifiedInput
let modifiedInput = input.getModifiedInput();
let modifiedInput = input.modifiedInput;
let res = this.getMatchingFileEditorInputFromInput(modifiedInput, arg);
if (res) {
return res;
}
// Second try originalInput
let originalInput = input.getOriginalInput();
return this.getMatchingFileEditorInputFromInput(originalInput, arg);
return this.getMatchingFileEditorInputFromInput(input.originalInput, arg);
}
private getMatchingFileEditorInputFromInput(input: EditorInput, deletedResource: URI): FileEditorInput;
......
......@@ -46,12 +46,12 @@ export class GitDiffEditorInput
return true;
}
var originalInput = this.getOriginalInput();
var originalInput = this.originalInput;
if (originalInput && originalInput.matches(otherInput)) {
return true;
}
var modifiedInput = this.getModifiedInput();
var modifiedInput = this.modifiedInput;
if (modifiedInput && modifiedInput.matches(otherInput)) {
return true;
}
......
......@@ -88,11 +88,9 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return true;
}
if (includeDiff) {
if (includeDiff && editor.input instanceof DiffEditorInput) {
let diffInput = <DiffEditorInput>editor.input;
if (types.isFunction(diffInput.getOriginalInput) && types.isFunction(diffInput.getModifiedInput)) {
return input.matches(diffInput.getModifiedInput()) || input.matches(diffInput.getOriginalInput());
}
return input.matches(diffInput.modifiedInput) || input.matches(diffInput.originalInput);
}
return false;
......@@ -270,12 +268,12 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
let originalModel = this.findModel(diffCodeEditor.getOriginalEditor(), input);
if (originalModel) {
return TPromise.as(diffInput.getOriginalInput());
return TPromise.as(diffInput.originalInput);
}
let modifiedModel = this.findModel(diffCodeEditor.getModifiedEditor(), input);
if (modifiedModel) {
return TPromise.as(diffInput.getModifiedInput());
return TPromise.as(diffInput.modifiedInput);
}
}
}
......
......@@ -60,8 +60,8 @@ suite('Workbench - EditorInput', () => {
let diffInput = new DiffEditorInput('name', 'description', input, otherInput);
assert.equal(diffInput.getOriginalInput(), input);
assert.equal(diffInput.getModifiedInput(), otherInput);
assert.equal(diffInput.originalInput, input);
assert.equal(diffInput.modifiedInput, otherInput);
assert(diffInput.matches(diffInput));
assert(!diffInput.matches(otherInput));
assert(!diffInput.matches(null));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册