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

diff editor: do not auto reveal first change when selection or viewstate is provided

上级 3e34503a
......@@ -107,11 +107,6 @@ export interface IResourceDiffInput extends IBaseResourceInput {
* The right hand side URI to open inside a diff editor.
*/
rightResource: URI;
/**
* Optional options to use when opening the text diff input.
*/
options?: ITextDiffEditorOptions;
}
export interface IResourceSideBySideInput extends IBaseResourceInput {
......@@ -301,13 +296,4 @@ export interface ITextEditorOptions extends IEditorOptions {
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.
*/
revealInCenterIfOutsideViewport?: boolean;
}
export interface ITextDiffEditorOptions extends ITextEditorOptions {
/**
* Whether to auto reveal the first change when the text editor is opened or not. By default
* the first change will not be revealed.
*/
autoRevealFirstChange: boolean;
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ import types = require('vs/base/common/types');
import { IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { BaseTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor';
import { TextEditorOptions, TextDiffEditorOptions, EditorInput, EditorOptions, TEXT_DIFF_EDITOR_ID, IFileEditorInput } from 'vs/workbench/common/editor';
import { TextEditorOptions, EditorInput, EditorOptions, TEXT_DIFF_EDITOR_ID, IFileEditorInput } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { DiffNavigator } from 'vs/editor/browser/widget/diffNavigator';
......@@ -151,26 +151,23 @@ export class TextDiffEditor extends BaseTextEditor {
const diffEditor = <IDiffEditor>this.getControl();
diffEditor.setModel((<TextDiffEditorModel>resolvedModel).textDiffEditorModel);
// Respect text diff editor options
let autoRevealFirstChange = true;
if (options instanceof TextDiffEditorOptions) {
const textDiffOptions = (<TextDiffEditorOptions>options);
autoRevealFirstChange = !types.isUndefinedOrNull(textDiffOptions.autoRevealFirstChange) ? textDiffOptions.autoRevealFirstChange : autoRevealFirstChange;
// Handle TextOptions
let alwaysRevealFirst = true;
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
const hadOptions = (<TextEditorOptions>options).apply(<IDiffEditor>diffEditor);
if (hadOptions) {
alwaysRevealFirst = false; // Do not reveal if we are instructed to open specific line/col
}
}
// listen on diff updated changes to reveal the first change
// Listen on diff updated changes to reveal the first change
this.diffNavigator = new DiffNavigator(diffEditor, {
alwaysRevealFirst: autoRevealFirstChange
alwaysRevealFirst
});
this.diffNavigator.addListener(DiffNavigator.Events.UPDATED, () => {
this.nextDiffAction.updateEnablement();
this.previousDiffAction.updateEnablement();
});
// Handle TextOptions
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
(<TextEditorOptions>options).apply(<IDiffEditor>diffEditor);
}
}, error => {
// In case we tried to open a file and the response indicates that this is not a text file, fallback to binary diff.
......
......@@ -11,7 +11,7 @@ import types = require('vs/base/common/types');
import URI from 'vs/base/common/uri';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { IEditor, IEditorViewState, IModel } from 'vs/editor/common/editorCommon';
import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position, Verbosity, ITextDiffEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position, Verbosity } from 'vs/platform/editor/common/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
......@@ -602,16 +602,9 @@ export class TextEditorOptions extends EditorOptions {
typeof input.options.revealInCenterIfOutsideViewport === 'boolean' ||
typeof input.options.pinned === 'boolean' ||
typeof input.options.inactive === 'boolean' ||
typeof input.options.index === 'number' ||
typeof (input.options as ITextDiffEditorOptions).autoRevealFirstChange === 'boolean'
typeof input.options.index === 'number'
) {
const textDiffOptions = input.options as ITextDiffEditorOptions;
if (typeof textDiffOptions.autoRevealFirstChange === 'boolean') {
options = new TextDiffEditorOptions();
(<TextDiffEditorOptions>options).autoRevealFirstChange = textDiffOptions.autoRevealFirstChange;
} else {
options = new TextEditorOptions();
}
options = new TextEditorOptions();
}
if (input.options.selection) {
......@@ -662,15 +655,7 @@ export class TextEditorOptions extends EditorOptions {
* Helper to create TextEditorOptions inline.
*/
public static create(settings: ITextEditorOptions = Object.create(null)): TextEditorOptions {
let options: TextEditorOptions;
const textDiffOptions = settings as ITextDiffEditorOptions;
if (typeof textDiffOptions.autoRevealFirstChange === 'boolean') {
options = new TextDiffEditorOptions();
(<TextDiffEditorOptions>options).autoRevealFirstChange = textDiffOptions.autoRevealFirstChange;
} else {
options = new TextEditorOptions();
}
const options = new TextEditorOptions();
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
......@@ -781,18 +766,6 @@ export class TextEditorOptions extends EditorOptions {
}
}
/**
* Base Text Diff Editor Options.
*/
export class TextDiffEditorOptions extends TextEditorOptions {
/**
* Whether to auto reveal the first change when the text editor is opened or not. By default
* the first change will not be revealed.
*/
public autoRevealFirstChange: boolean;
}
export interface IStacksModelChangeEvent {
group: IEditorGroup;
editor?: IEditorInput;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册