@@ -39,9 +39,9 @@ export class TextEditorState {
3939
4040 private static readonly EDITOR_SELECTION_THRESHOLD = 10 ; // number of lines to move in editor to justify for new state
4141
42- private textEditorSelection : ITextEditorSelection ;
42+ private textEditorSelection ? : ITextEditorSelection ;
4343
44- constructor ( private _editorInput : IEditorInput , private _selection : Selection ) {
44+ constructor ( private _editorInput : IEditorInput , private _selection : Selection | null ) {
4545 this . textEditorSelection = Selection . isISelection ( _selection ) ? {
4646 startLineNumber : _selection . startLineNumber ,
4747 startColumn : _selection . startColumn
@@ -52,7 +52,7 @@ export class TextEditorState {
5252 return this . _editorInput ;
5353 }
5454
55- get selection ( ) : ITextEditorSelection {
55+ get selection ( ) : ITextEditorSelection | undefined {
5656 return this . textEditorSelection ;
5757 }
5858
@@ -105,7 +105,7 @@ export class HistoryService extends Disposable implements IHistoryService {
105105 private static readonly MAX_RECENTLY_CLOSED_EDITORS = 20 ;
106106
107107 private activeEditorListeners : IDisposable [ ] ;
108- private lastActiveEditor : IEditorIdentifier ;
108+ private lastActiveEditor ? : IEditorIdentifier ;
109109
110110 private editorHistoryListeners : Map < EditorInput , IDisposable [ ] > = new Map ( ) ;
111111 private editorStackListeners : Map < EditorInput , IDisposable [ ] > = new Map ( ) ;
@@ -114,7 +114,7 @@ export class HistoryService extends Disposable implements IHistoryService {
114114 private index : number ;
115115 private lastIndex : number ;
116116 private navigatingInStack : boolean ;
117- private currentTextEditorState : TextEditorState ;
117+ private currentTextEditorState : TextEditorState | null ;
118118
119119 private lastEditLocation : IStackEntry ;
120120
@@ -156,7 +156,7 @@ export class HistoryService extends Disposable implements IHistoryService {
156156 this . loaded = false ;
157157 this . resourceFilter = this . _register ( instantiationService . createInstance (
158158 ResourceGlobMatcher ,
159- ( root : URI ) => this . getExcludes ( root ) ,
159+ ( root ? : URI ) => this . getExcludes ( root ) ,
160160 ( event : IConfigurationChangeEvent ) => event . affectsConfiguration ( FILES_EXCLUDE_CONFIG ) || event . affectsConfiguration ( 'search.exclude' )
161161 ) ) ;
162162
@@ -166,7 +166,7 @@ export class HistoryService extends Disposable implements IHistoryService {
166166 private getExcludes ( root ?: URI ) : IExpression {
167167 const scope = root ? { resource : root } : undefined ;
168168
169- return getExcludes ( this . configurationService . getValue < ISearchConfiguration > ( scope ) ) ;
169+ return getExcludes ( scope ? this . configurationService . getValue < ISearchConfiguration > ( scope ) : this . configurationService . getValue < ISearchConfiguration > ( ) ) ! ;
170170 }
171171
172172 private registerListeners ( ) : void {
@@ -192,7 +192,7 @@ export class HistoryService extends Disposable implements IHistoryService {
192192 }
193193
194194 // Remember as last active editor (can be undefined if none opened)
195- this . lastActiveEditor = activeControl ? { editor : activeControl . input , groupId : activeControl . group . id } : undefined ;
195+ this . lastActiveEditor = activeControl && activeControl . input && activeControl . group ? { editor : activeControl . input , groupId : activeControl . group . id } : undefined ;
196196
197197 // Dispose old listeners
198198 dispose ( this . activeEditorListeners ) ;
@@ -254,7 +254,7 @@ export class HistoryService extends Disposable implements IHistoryService {
254254 if ( ! event . replaced ) {
255255 const resource = event . editor ? event . editor . getResource ( ) : undefined ;
256256 const supportsReopen = resource && this . fileService . canHandleResource ( resource ) ; // we only support file'ish things to reopen
257- if ( supportsReopen ) {
257+ if ( resource && supportsReopen ) {
258258
259259 // Remove all inputs matching and add as last recently closed
260260 this . removeFromRecentlyClosedFiles ( event . editor ) ;
@@ -452,7 +452,7 @@ export class HistoryService extends Disposable implements IHistoryService {
452452
453453 // Respect max entries setting
454454 if ( this . history . length > HistoryService . MAX_HISTORY_ITEMS ) {
455- this . clearOnEditorDispose ( this . history . pop ( ) , this . editorHistoryListeners ) ;
455+ this . clearOnEditorDispose ( this . history . pop ( ) ! , this . editorHistoryListeners ) ;
456456 }
457457
458458 // Remove this from the history unless the history input is a resource
@@ -537,15 +537,15 @@ export class HistoryService extends Disposable implements IHistoryService {
537537 } ) ;
538538 }
539539
540- private handleEditorEventInStack ( control : IBaseEditor , event ?: ICursorPositionChangedEvent ) : void {
540+ private handleEditorEventInStack ( control : IBaseEditor | undefined , event ?: ICursorPositionChangedEvent ) : void {
541541 const codeEditor = control ? getCodeEditor ( control . getControl ( ) ) : undefined ;
542542
543543 // treat editor changes that happen as part of stack navigation specially
544544 // we do not want to add a new stack entry as a matter of navigating the
545545 // stack but we need to keep our currentTextEditorState up to date with
546546 // the navigtion that occurs.
547547 if ( this . navigatingInStack ) {
548- if ( codeEditor && control . input ) {
548+ if ( codeEditor && control && control . input ) {
549549 this . currentTextEditorState = new TextEditorState ( control . input , codeEditor . getSelection ( ) ) ;
550550 } else {
551551 this . currentTextEditorState = null ; // we navigated to a non text editor
@@ -556,7 +556,7 @@ export class HistoryService extends Disposable implements IHistoryService {
556556 else {
557557
558558 // navigation inside text editor
559- if ( codeEditor && control . input ) {
559+ if ( codeEditor && control && control . input ) {
560560 this . handleTextEditorEvent ( control , codeEditor , event ) ;
561561 }
562562
@@ -572,6 +572,10 @@ export class HistoryService extends Disposable implements IHistoryService {
572572 }
573573
574574 private handleTextEditorEvent ( editor : IBaseEditor , editorControl : IEditor , event ?: ICursorPositionChangedEvent ) : void {
575+ if ( ! editor . input ) {
576+ return ;
577+ }
578+
575579 const stateCandidate = new TextEditorState ( editor . input , editorControl . getSelection ( ) ) ;
576580
577581 // Add to stack if we dont have a current state or this new state justifies a push
@@ -589,6 +593,10 @@ export class HistoryService extends Disposable implements IHistoryService {
589593 }
590594
591595 private handleNonTextEditorEvent ( editor : IBaseEditor ) : void {
596+ if ( ! editor . input ) {
597+ return ;
598+ }
599+
592600 const currentStack = this . stack [ this . index ] ;
593601 if ( currentStack && this . matches ( editor . input , currentStack . input ) ) {
594602 return ; // do not push same editor input again
@@ -656,7 +664,7 @@ export class HistoryService extends Disposable implements IHistoryService {
656664
657665 // Check for limit
658666 if ( this . stack . length > HistoryService . MAX_STACK_ITEMS ) {
659- removedEntries . push ( this . stack . shift ( ) ) ; // remove first
667+ removedEntries . push ( this . stack . shift ( ) ! ) ; // remove first
660668 if ( this . lastIndex >= 0 ) {
661669 this . lastIndex -- ;
662670 }
@@ -691,7 +699,7 @@ export class HistoryService extends Disposable implements IHistoryService {
691699 return true ;
692700 }
693701
694- if ( ( ! selectionA && selectionB ) || ( selectionA && ! selectionB ) ) {
702+ if ( ! selectionA || ! selectionB ) {
695703 return false ;
696704 }
697705
@@ -859,7 +867,7 @@ export class HistoryService extends Disposable implements IHistoryService {
859867 } ) ) ;
860868 }
861869
862- private safeLoadHistoryEntry ( registry : IEditorInputFactoryRegistry , entry : ISerializedEditorHistoryEntry ) : IEditorInput | IResourceInput {
870+ private safeLoadHistoryEntry ( registry : IEditorInputFactoryRegistry , entry : ISerializedEditorHistoryEntry ) : IEditorInput | IResourceInput | undefined {
863871 const serializedEditorHistoryEntry = entry as ISerializedEditorHistoryEntry ;
864872
865873 // File resource: via URI.revive()
@@ -884,7 +892,7 @@ export class HistoryService extends Disposable implements IHistoryService {
884892 return undefined ;
885893 }
886894
887- getLastActiveWorkspaceRoot ( schemeFilter ?: string ) : URI {
895+ getLastActiveWorkspaceRoot ( schemeFilter ?: string ) : URI | undefined {
888896
889897 // No Folder: return early
890898 const folders = this . contextService . getWorkspace ( ) . folders ;
@@ -931,10 +939,10 @@ export class HistoryService extends Disposable implements IHistoryService {
931939 return undefined ;
932940 }
933941
934- getLastActiveFile ( schemeFilter : string ) : URI {
942+ getLastActiveFile ( schemeFilter : string ) : URI | undefined {
935943 const history = this . getHistory ( ) ;
936944 for ( const input of history ) {
937- let resource : URI ;
945+ let resource : URI | null ;
938946 if ( input instanceof EditorInput ) {
939947 resource = toResource ( input , { filter : schemeFilter } ) ;
940948 } else {
0 commit comments