@@ -111,7 +111,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
111111 private _replaceFocusTracker : dom . IFocusTracker ;
112112 private _replaceInputFocused : IContextKey < boolean > ;
113113 private _viewZone : FindWidgetViewZone ;
114- private _viewZoneId : number ;
114+ private _viewZoneId ? : number ;
115115
116116 private _resizeSash : Sash ;
117117 private _resized : boolean ;
@@ -210,7 +210,9 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
210210 return ;
211211 }
212212 this . _codeEditor . changeViewZones ( ( accessor ) => {
213- accessor . removeZone ( this . _viewZoneId ) ;
213+ if ( this . _viewZoneId ) {
214+ accessor . removeZone ( this . _viewZoneId ) ;
215+ }
214216 this . _viewZoneId = undefined ;
215217 } ) ;
216218 } ) ) ;
@@ -239,7 +241,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
239241 return this . _domNode ;
240242 }
241243
242- public getPosition ( ) : IOverlayWidgetPosition {
244+ public getPosition ( ) : IOverlayWidgetPosition | null {
243245 if ( this . _isVisible ) {
244246 return {
245247 preference : OverlayWidgetPositionPreference . TOP_RIGHT_CORNER
@@ -401,8 +403,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
401403 if ( ! this . _isVisible ) {
402404 this . _isVisible = true ;
403405
404- let selection = this . _codeEditor . getSelection ( ) ;
405- let isSelection = selection ? ( selection . startLineNumber !== selection . endLineNumber || selection . startColumn !== selection . endColumn ) : false ;
406+ const selection = this . _codeEditor . getSelection ( ) ;
407+ const isSelection = selection ? ( selection . startLineNumber !== selection . endLineNumber || selection . startColumn !== selection . endColumn ) : false ;
406408 if ( isSelection && this . _codeEditor . getConfiguration ( ) . contribInfo . find . autoFindInSelection ) {
407409 this . _toggleSelectionFind . checked = true ;
408410 } else {
@@ -425,24 +427,27 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
425427
426428 let adjustEditorScrollTop = true ;
427429 if ( this . _codeEditor . getConfiguration ( ) . contribInfo . find . seedSearchStringFromSelection && selection ) {
428- let editorCoords = dom . getDomNodePagePosition ( this . _codeEditor . getDomNode ( ) ) ;
429- let startCoords = this . _codeEditor . getScrolledVisiblePosition ( selection . getStartPosition ( ) ) ;
430- let startLeft = editorCoords . left + startCoords . left ;
431- let startTop = startCoords . top ;
432-
433- if ( startTop < this . _viewZone . heightInPx ) {
434- if ( selection . endLineNumber > selection . startLineNumber ) {
435- adjustEditorScrollTop = false ;
436- }
430+ const domNode = this . _codeEditor . getDomNode ( ) ;
431+ if ( domNode ) {
432+ const editorCoords = dom . getDomNodePagePosition ( domNode ) ;
433+ const startCoords = this . _codeEditor . getScrolledVisiblePosition ( selection . getStartPosition ( ) ) ;
434+ const startLeft = editorCoords . left + ( startCoords ? startCoords . left : 0 ) ;
435+ const startTop = startCoords ? startCoords . top : 0 ;
436+
437+ if ( startTop < this . _viewZone . heightInPx ) {
438+ if ( selection . endLineNumber > selection . startLineNumber ) {
439+ adjustEditorScrollTop = false ;
440+ }
437441
438- let leftOfFindWidget = dom . getTopLeftOffset ( this . _domNode ) . left ;
439- if ( startLeft > leftOfFindWidget ) {
440- adjustEditorScrollTop = false ;
441- }
442- let endCoords = this . _codeEditor . getScrolledVisiblePosition ( selection . getEndPosition ( ) ) ;
443- let endLeft = editorCoords . left + endCoords . left ;
444- if ( endLeft > leftOfFindWidget ) {
445- adjustEditorScrollTop = false ;
442+ const leftOfFindWidget = dom . getTopLeftOffset ( this . _domNode ) . left ;
443+ if ( startLeft > leftOfFindWidget ) {
444+ adjustEditorScrollTop = false ;
445+ }
446+ const endCoords = this . _codeEditor . getScrolledVisiblePosition ( selection . getEndPosition ( ) ) ;
447+ const endLeft = editorCoords . left + ( endCoords ? endCoords . left : 0 ) ;
448+ if ( endLeft > leftOfFindWidget ) {
449+ adjustEditorScrollTop = false ;
450+ }
446451 }
447452 }
448453 }
@@ -609,12 +614,16 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
609614 }
610615
611616 private _updateSearchScope ( ) : void {
617+ if ( ! this . _codeEditor . hasModel ( ) ) {
618+ return ;
619+ }
620+
612621 if ( this . _toggleSelectionFind . checked ) {
613622 let selection = this . _codeEditor . getSelection ( ) ;
614623 if ( selection . endColumn === 1 && selection . endLineNumber > selection . startLineNumber ) {
615624 selection = selection . setEndPosition ( selection . endLineNumber - 1 , this . _codeEditor . getModel ( ) . getLineMaxColumn ( selection . endLineNumber - 1 ) ) ;
616625 }
617- let currentMatch = this . _state . currentMatch ;
626+ const currentMatch = this . _state . currentMatch ;
618627 if ( selection . startLineNumber !== selection . endLineNumber ) {
619628 if ( ! Range . equalsRange ( selection , currentMatch ) ) {
620629 // Reseed find scope
@@ -725,7 +734,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
725734 appendCaseSensitiveLabel : this . _keybindingLabelFor ( FIND_IDS . ToggleCaseSensitiveCommand ) ,
726735 appendWholeWordsLabel : this . _keybindingLabelFor ( FIND_IDS . ToggleWholeWordCommand ) ,
727736 appendRegexLabel : this . _keybindingLabelFor ( FIND_IDS . ToggleRegexCommand ) ,
728- validation : ( value : string ) : InputBoxMessage => {
737+ validation : ( value : string ) : InputBoxMessage | null => {
729738 if ( value . length === 0 ) {
730739 return null ;
731740 }
@@ -806,15 +815,17 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
806815 title : NLS_TOGGLE_SELECTION_FIND_TITLE + this . _keybindingLabelFor ( FIND_IDS . ToggleSearchScopeCommand ) ,
807816 onChange : ( ) => {
808817 if ( this . _toggleSelectionFind . checked ) {
809- let selection = this . _codeEditor . getSelection ( ) ;
810- if ( selection . endColumn === 1 && selection . endLineNumber > selection . startLineNumber ) {
811- selection = selection . setEndPosition ( selection . endLineNumber - 1 , this . _codeEditor . getModel ( ) . getLineMaxColumn ( selection . endLineNumber - 1 ) ) ;
812- }
813- if ( ! selection . isEmpty ( ) ) {
814- this . _state . change ( { searchScope : selection } , true ) ;
818+ if ( this . _codeEditor . hasModel ( ) ) {
819+ let selection = this . _codeEditor . getSelection ( ) ;
820+ if ( selection . endColumn === 1 && selection . endLineNumber > selection . startLineNumber ) {
821+ selection = selection . setEndPosition ( selection . endLineNumber - 1 , this . _codeEditor . getModel ( ) . getLineMaxColumn ( selection . endLineNumber - 1 ) ) ;
822+ }
823+ if ( ! selection . isEmpty ( ) ) {
824+ this . _state . change ( { searchScope : selection } , true ) ;
825+ }
815826 }
816827 } else {
817- this . _state . change ( { searchScope : null } , true ) ;
828+ this . _state . change ( { searchScope : undefined } , true ) ;
818829 }
819830 }
820831 } ) ) ;
@@ -824,7 +835,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
824835 label : NLS_CLOSE_BTN_LABEL + this . _keybindingLabelFor ( FIND_IDS . CloseFindWidgetCommand ) ,
825836 className : 'close-fw' ,
826837 onTrigger : ( ) => {
827- this . _state . change ( { isRevealed : false , searchScope : null } , false ) ;
838+ this . _state . change ( { isRevealed : false , searchScope : undefined } , false ) ;
828839 } ,
829840 onKeyDown : ( e ) => {
830841 if ( e . equals ( KeyCode . Tab ) ) {
@@ -850,7 +861,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
850861 let replaceInput = document . createElement ( 'div' ) ;
851862 replaceInput . className = 'replace-input' ;
852863 replaceInput . style . width = REPLACE_INPUT_AREA_WIDTH + 'px' ;
853- this . _replaceInputBox = this . _register ( new ContextScopedHistoryInputBox ( replaceInput , null , {
864+ this . _replaceInputBox = this . _register ( new ContextScopedHistoryInputBox ( replaceInput , void 0 , {
854865 ariaLabel : NLS_REPLACE_INPUT_LABEL ,
855866 placeholder : NLS_REPLACE_INPUT_PLACEHOLDER ,
856867 history : [ ]
@@ -950,8 +961,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
950961 return ;
951962 }
952963
953- let inputBoxWidth = width - FIND_ALL_CONTROLS_WIDTH ;
954- let maxWidth = parseFloat ( dom . getComputedStyle ( this . _domNode ) . maxWidth ) || 0 ;
964+ const inputBoxWidth = width - FIND_ALL_CONTROLS_WIDTH ;
965+ const maxWidth = parseFloat ( dom . getComputedStyle ( this . _domNode ) . maxWidth ! ) || 0 ;
955966 if ( width > maxWidth ) {
956967 return ;
957968 }
@@ -1119,7 +1130,7 @@ export class SimpleButton extends Widget {
11191130// theming
11201131
11211132registerThemingParticipant ( ( theme , collector ) => {
1122- const addBackgroundColorRule = ( selector : string , color : Color ) : void => {
1133+ const addBackgroundColorRule = ( selector : string , color : Color | null ) : void => {
11231134 if ( color ) {
11241135 collector . addRule ( `.monaco-editor ${ selector } { background-color: ${ color } ; }` ) ;
11251136 }
0 commit comments