@@ -157,6 +157,31 @@ function doSearch(ctx, rev, query, keepSelection, modifiers: SearchModifiers) {
157157 } ) ;
158158}
159159
160+ export function searchSourceForHighlight (
161+ ctx : Object ,
162+ rev : boolean ,
163+ query : string ,
164+ keepSelection : boolean ,
165+ modifiers : SearchModifiers ,
166+ line : number ,
167+ ch : number
168+ ) {
169+ const { cm } = ctx ;
170+ if ( ! cm ) {
171+ return ;
172+ }
173+
174+ return cm . operation ( function ( ) {
175+ const state = getSearchState ( cm , query ) ;
176+ const isNewQuery = state . query !== query ;
177+ state . query = query ;
178+
179+ updateOverlay ( cm , state , query , modifiers ) ;
180+ updateCursor ( cm , state , keepSelection ) ;
181+ findNextOnLine ( ctx , rev , query , isNewQuery , modifiers , line , ch ) ;
182+ } ) ;
183+ }
184+
160185function getCursorPos ( newQuery , rev , state ) {
161186 if ( newQuery ) {
162187 return rev ? state . posFrom : state . posTo ;
@@ -208,6 +233,28 @@ function searchNext(ctx, rev, query, newQuery, modifiers) {
208233 return nextMatch ;
209234}
210235
236+ function findNextOnLine ( ctx , rev , query , newQuery , modifiers , line , ch ) {
237+ const { cm, ed } = ctx ;
238+ cm . operation ( function ( ) {
239+ const pos = { line : line - 1 , ch } ;
240+ let cursor = getSearchCursor ( cm , query , pos , modifiers ) ;
241+
242+ if ( ! cursor . find ( rev ) && query ) {
243+ cursor = getSearchCursor ( cm , query , pos , modifiers ) ;
244+ if ( ! cursor . find ( rev ) ) {
245+ return ;
246+ }
247+ }
248+
249+ // We don't want to jump the editor
250+ // when we're selecting text
251+ if ( ! cm . state . selectingText ) {
252+ ed . alignLine ( cursor . from ( ) . line , "center" ) ;
253+ cm . setSelection ( cursor . from ( ) , cursor . to ( ) ) ;
254+ }
255+ } ) ;
256+ }
257+
211258/**
212259 * Remove overlay.
213260 *
0 commit comments