@@ -91,9 +91,10 @@ export class SearchEngine {
9191 * Find the next occurrence of a term with wrapping and selection management.
9292 * @param term The search term.
9393 * @param searchOptions Search options.
94+ * @param cachedSearchTerm The cached search term to determine incremental behavior.
9495 * @returns The search result if found, undefined otherwise.
9596 */
96- public findNextWithSelection ( term : string , searchOptions ?: ISearchOptions ) : ISearchResult | undefined {
97+ public findNextWithSelection ( term : string , searchOptions ?: ISearchOptions , cachedSearchTerm ?: string ) : ISearchResult | undefined {
9798 if ( ! term || term . length === 0 ) {
9899 this . _terminal . clearSelection ( ) ;
99100 return undefined ;
@@ -105,8 +106,13 @@ export class SearchEngine {
105106 let startCol = 0 ;
106107 let startRow = 0 ;
107108 if ( prevSelectedPos ) {
108- startCol = prevSelectedPos . end . x ;
109- startRow = prevSelectedPos . end . y ;
109+ if ( cachedSearchTerm === term ) {
110+ startCol = prevSelectedPos . end . x ;
111+ startRow = prevSelectedPos . end . y ;
112+ } else {
113+ startCol = prevSelectedPos . start . x ;
114+ startRow = prevSelectedPos . start . y ;
115+ }
110116 }
111117
112118 this . _lineCache . initLinesCache ( ) ;
@@ -155,9 +161,10 @@ export class SearchEngine {
155161 * Find the previous occurrence of a term with wrapping and selection management.
156162 * @param term The search term.
157163 * @param searchOptions Search options.
164+ * @param cachedSearchTerm The cached search term to determine if expansion should occur.
158165 * @returns The search result if found, undefined otherwise.
159166 */
160- public findPreviousWithSelection ( term : string , searchOptions ?: ISearchOptions ) : ISearchResult | undefined {
167+ public findPreviousWithSelection ( term : string , searchOptions ?: ISearchOptions , cachedSearchTerm ?: string ) : ISearchResult | undefined {
161168 if ( ! term || term . length === 0 ) {
162169 this . _terminal . clearSelection ( ) ;
163170 return undefined ;
@@ -180,12 +187,14 @@ export class SearchEngine {
180187 if ( prevSelectedPos ) {
181188 searchPosition . startRow = startRow = prevSelectedPos . start . y ;
182189 searchPosition . startCol = startCol = prevSelectedPos . start . x ;
183- // Try to expand selection to right first.
184- result = this . _findInLine ( term , searchPosition , searchOptions , false ) ;
185- if ( ! result ) {
186- // If selection was not able to be expanded to the right, then try reverse search
187- searchPosition . startRow = startRow = prevSelectedPos . end . y ;
188- searchPosition . startCol = startCol = prevSelectedPos . end . x ;
190+ if ( cachedSearchTerm !== term ) {
191+ // Try to expand selection to right first.
192+ result = this . _findInLine ( term , searchPosition , searchOptions , false ) ;
193+ if ( ! result ) {
194+ // If selection was not able to be expanded to the right, then try reverse search
195+ searchPosition . startRow = startRow = prevSelectedPos . end . y ;
196+ searchPosition . startCol = startCol = prevSelectedPos . end . x ;
197+ }
189198 }
190199 }
191200
0 commit comments