@@ -121,7 +121,7 @@ export class FileMatch extends Disposable {
121121 this . _resource = this . rawMatch . resource ;
122122 this . _matches = new LinkedMap < string , Match > ( ) ;
123123 this . _removedMatches = new ArraySet < string > ( ) ;
124- this . _updateScheduler = new RunOnceScheduler ( this . updateMatches . bind ( this ) , 250 ) ;
124+ this . _updateScheduler = new RunOnceScheduler ( this . updateMatchesForModel . bind ( this ) , 250 ) ;
125125
126126 this . createMatches ( ) ;
127127 this . registerListeners ( ) ;
@@ -131,7 +131,7 @@ export class FileMatch extends Disposable {
131131 let model = this . modelService . getModel ( this . _resource ) ;
132132 if ( model ) {
133133 this . bindModel ( model ) ;
134- this . updateMatches ( ) ;
134+ this . updateMatchesForModel ( ) ;
135135 } else {
136136 this . rawMatch . lineMatches . forEach ( ( rawLineMatch ) => {
137137 rawLineMatch . offsetAndLengths . forEach ( offsetAndLength => {
@@ -161,7 +161,7 @@ export class FileMatch extends Disposable {
161161
162162 private onModelWillDispose ( ) : void {
163163 // Update matches because model might have some dirty changes
164- this . updateMatches ( ) ;
164+ this . updateMatchesForModel ( ) ;
165165 this . unbindModel ( ) ;
166166 }
167167
@@ -174,7 +174,7 @@ export class FileMatch extends Disposable {
174174 }
175175 }
176176
177- private updateMatches ( ) : void {
177+ private updateMatchesForModel ( ) : void {
178178 // this is called from a timeout and might fire
179179 // after the model has been disposed
180180 if ( ! this . _model ) {
@@ -184,6 +184,24 @@ export class FileMatch extends Disposable {
184184 let matches = this . _model
185185 . findMatches ( this . _query . pattern , this . _model . getFullModelRange ( ) , this . _query . isRegExp , this . _query . isCaseSensitive , this . _query . isWordMatch ) ;
186186
187+ this . updateMatches ( matches ) ;
188+ }
189+
190+ private updatesMatchesForLine ( lineNumber : number ) : void {
191+ const range = {
192+ startLineNumber : lineNumber ,
193+ startColumn : this . _model . getLineMinColumn ( lineNumber ) ,
194+ endLineNumber : lineNumber ,
195+ endColumn : this . _model . getLineMaxColumn ( lineNumber )
196+ } ;
197+ const oldMatches = this . _matches . values ( ) . filter ( match => match . range ( ) . startLineNumber === lineNumber ) ;
198+ oldMatches . forEach ( match => this . _matches . delete ( match . id ( ) ) ) ;
199+
200+ const matches = this . _model . findMatches ( this . _query . pattern , range , this . _query . isRegExp , this . _query . isCaseSensitive , this . _query . isWordMatch ) ;
201+ this . updateMatches ( matches ) ;
202+ }
203+
204+ private updateMatches ( matches : Range [ ] ) {
187205 matches . forEach ( range => {
188206 let match = new Match ( this , this . _model . getLineContent ( range . startLineNumber ) , range . startLineNumber - 1 , range . startColumn - 1 , range . endColumn - range . startColumn ) ;
189207 if ( ! this . _removedMatches . contains ( match . id ( ) ) ) {
@@ -231,11 +249,9 @@ export class FileMatch extends Disposable {
231249 this . _onChange . fire ( false ) ;
232250 }
233251
234- public replace ( match : Match ) : TPromise < any > {
235- return this . replaceService . replace ( match ) . then ( ( ) => {
236- this . removeMatch ( match ) ;
237- this . _onChange . fire ( false ) ;
238- } ) ;
252+ public replace ( toReplace : Match ) : TPromise < void > {
253+ return this . replaceService . replace ( toReplace )
254+ . then ( ( ) => this . updatesMatchesForLine ( toReplace . range ( ) . startLineNumber ) ) ;
239255 }
240256
241257 public setSelectedMatch ( match : Match ) {
0 commit comments