55
66import * as nls from 'vs/nls' ;
77import * as objects from 'vs/base/common/objects' ;
8- import * as types from 'vs/base/common/types' ;
8+ import { isFunction , isObject , isArray } from 'vs/base/common/types' ;
99import { IDiffEditor } from 'vs/editor/browser/editorBrowser' ;
1010import { IDiffEditorOptions , IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions' ;
1111import { BaseTextEditor , IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor' ;
@@ -31,7 +31,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
3131import { CancellationToken } from 'vs/base/common/cancellation' ;
3232import { EditorMemento } from 'vs/workbench/browser/parts/editor/baseEditor' ;
3333import { IWindowService } from 'vs/platform/windows/common/windows' ;
34- import { EditorActivation } from 'vs/platform/editor/common/editor' ;
34+ import { EditorActivation , IEditorOptions } from 'vs/platform/editor/common/editor' ;
3535
3636/**
3737 * The text editor that leverages the diff text editor for the editing experience.
@@ -73,7 +73,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
7373 return this . instantiationService . createInstance ( DiffEditorWidget , parent , configuration ) ;
7474 }
7575
76- async setInput ( input : EditorInput , options : EditorOptions , token : CancellationToken ) : Promise < void > {
76+ async setInput ( input : EditorInput , options : EditorOptions | undefined , token : CancellationToken ) : Promise < void > {
7777
7878 // Dispose previous diff navigator
7979 this . diffNavigatorDisposables . clear ( ) ;
@@ -104,7 +104,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
104104
105105 // Apply Options from TextOptions
106106 let optionsGotApplied = false ;
107- if ( options && types . isFunction ( ( < TextEditorOptions > options ) . apply ) ) {
107+ if ( options && isFunction ( ( < TextEditorOptions > options ) . apply ) ) {
108108 optionsGotApplied = ( < TextEditorOptions > options ) . apply ( diffEditor , ScrollType . Immediate ) ;
109109 }
110110
@@ -133,9 +133,9 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
133133 }
134134 }
135135
136- setOptions ( options : EditorOptions ) : void {
136+ setOptions ( options : EditorOptions | undefined ) : void {
137137 const textOptions = < TextEditorOptions > options ;
138- if ( textOptions && types . isFunction ( textOptions . apply ) ) {
138+ if ( textOptions && isFunction ( textOptions . apply ) ) {
139139 textOptions . apply ( this . getControl ( ) , ScrollType . Smooth ) ;
140140 }
141141 }
@@ -156,7 +156,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
156156 return false ;
157157 }
158158
159- private openAsBinary ( input : EditorInput , options : EditorOptions ) : boolean {
159+ private openAsBinary ( input : EditorInput , options : EditorOptions | undefined ) : boolean {
160160 if ( input instanceof DiffEditorInput ) {
161161 const originalInput = input . originalInput ;
162162 const modifiedInput = input . modifiedInput ;
@@ -177,7 +177,12 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
177177 // because we are triggering another openEditor() call
178178 // and do not control the initial intent that resulted
179179 // in us now opening as binary.
180- options . overwrite ( { activation : EditorActivation . PRESERVE } ) ;
180+ const preservingOptions : IEditorOptions = { activation : EditorActivation . PRESERVE } ;
181+ if ( options ) {
182+ options . overwrite ( preservingOptions ) ;
183+ } else {
184+ options = EditorOptions . create ( preservingOptions ) ;
185+ }
181186
182187 this . editorService . openEditor ( binaryDiffInput , options , this . group ) ;
183188
@@ -191,7 +196,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
191196 const editorConfiguration = super . computeConfiguration ( configuration ) ;
192197
193198 // Handle diff editor specially by merging in diffEditor configuration
194- if ( types . isObject ( configuration . diffEditor ) ) {
199+ if ( isObject ( configuration . diffEditor ) ) {
195200 objects . mixin ( editorConfiguration , configuration . diffEditor ) ;
196201 }
197202
@@ -233,7 +238,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
233238 private isFileBinaryError ( error : Error [ ] ) : boolean ;
234239 private isFileBinaryError ( error : Error ) : boolean ;
235240 private isFileBinaryError ( error : Error | Error [ ] ) : boolean {
236- if ( types . isArray ( error ) ) {
241+ if ( isArray ( error ) ) {
237242 const errors = < Error [ ] > error ;
238243
239244 return errors . some ( e => this . isFileBinaryError ( e ) ) ;
@@ -269,7 +274,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
269274 return super . loadTextEditorViewState ( resource ) as IDiffEditorViewState ; // overridden for text diff editor support
270275 }
271276
272- private saveTextDiffEditorViewState ( input : EditorInput | null ) : void {
277+ private saveTextDiffEditorViewState ( input : EditorInput | undefined ) : void {
273278 if ( ! ( input instanceof DiffEditorInput ) ) {
274279 return ; // only supported for diff editor inputs
275280 }
0 commit comments