@@ -63,11 +63,32 @@ interface IMultiHighlight extends IDisposable {
6363 match : ISearchResult ;
6464}
6565
66- const NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?' ;
67- const LINES_CACHE_TIME_TO_LIVE = 15 * 1000 ; // 15 secs
68- const DEFAULT_HIGHLIGHT_LIMIT = 1000 ;
66+ /**
67+ * Configuration constants for the search addon functionality.
68+ */
69+ const enum Constants {
70+ /**
71+ * Characters that are considered non-word characters for search boundary detection. These
72+ * characters are used to determine word boundaries when performing whole-word searches. Includes
73+ * common punctuation, symbols, and whitespace characters.
74+ */
75+ NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?' ,
76+
77+ /**
78+ * Time-to-live for cached search results in milliseconds. After this duration, cached search
79+ * results will be invalidated to ensure they remain consistent with terminal content changes.
80+ */
81+ LINES_CACHE_TIME_TO_LIVE = 15000 ,
82+
83+ /**
84+ * Default maximum number of search results to highlight simultaneously. This limit prevents
85+ * performance degradation when searching for very common terms that would result in excessive
86+ * highlighting decorations.
87+ */
88+ DEFAULT_HIGHLIGHT_LIMIT = 1000
89+ }
6990
70- export class SearchAddon extends Disposable implements ITerminalAddon , ISearchApi {
91+ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchApi {
7192 private _terminal : Terminal | undefined ;
7293 private _cachedSearchTerm : string | undefined ;
7394 private _highlightedLines : Set < number > = new Set ( ) ;
@@ -92,7 +113,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
92113 constructor ( options ?: Partial < ISearchAddonOptions > ) {
93114 super ( ) ;
94115
95- this . _highlightLimit = options ?. highlightLimit ?? DEFAULT_HIGHLIGHT_LIMIT ;
116+ this . _highlightLimit = options ?. highlightLimit ?? Constants . DEFAULT_HIGHLIGHT_LIMIT ;
96117 }
97118
98119 public activate ( terminal : Terminal ) : void {
@@ -446,7 +467,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
446467 }
447468
448469 window . clearTimeout ( this . _linesCacheTimeoutId ) ;
449- this . _linesCacheTimeoutId = window . setTimeout ( ( ) => this . _destroyLinesCache ( ) , LINES_CACHE_TIME_TO_LIVE ) ;
470+ this . _linesCacheTimeoutId = window . setTimeout ( ( ) => this . _destroyLinesCache ( ) , Constants . LINES_CACHE_TIME_TO_LIVE ) ;
450471 }
451472
452473 private _destroyLinesCache ( ) : void {
@@ -466,8 +487,8 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
466487 * @param term the substring that starts at searchIndex
467488 */
468489 private _isWholeWord ( searchIndex : number , line : string , term : string ) : boolean {
469- return ( ( searchIndex === 0 ) || ( NON_WORD_CHARACTERS . includes ( line [ searchIndex - 1 ] ) ) ) &&
470- ( ( ( searchIndex + term . length ) === line . length ) || ( NON_WORD_CHARACTERS . includes ( line [ searchIndex + term . length ] ) ) ) ;
490+ return ( ( searchIndex === 0 ) || ( Constants . NON_WORD_CHARACTERS . includes ( line [ searchIndex - 1 ] ) ) ) &&
491+ ( ( ( searchIndex + term . length ) === line . length ) || ( Constants . NON_WORD_CHARACTERS . includes ( line [ searchIndex + term . length ] ) ) ) ;
471492 }
472493
473494 /**
0 commit comments