Skip to content

Commit be2d5e6

Browse files
committed
microsoft#14167 Fix replace part
- Disable replace action - Do not remove the match to replace. Model update does it anyways - Update the matches for the line after replace
1 parent 5834bb3 commit be2d5e6

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/vs/workbench/parts/search/browser/searchActions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
380380
}
381381

382382
public run(): TPromise<any> {
383+
this.enabled = false;
383384
this.telemetryService.publicLog('replace.action.selected');
384385
let elementToFocus = this.getElementToFocusAfterRemoved(this.viewer, this.element);
385386
let elementToShowReplacePreview = this.getElementToShowReplacePreview(elementToFocus);
@@ -388,7 +389,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
388389
if (elementToFocus) {
389390
this.viewer.setFocus(elementToFocus);
390391
}
391-
this.viewer.DOMFocus();
392+
this.viewer.DOMFocus();
392393
if (!elementToShowReplacePreview || this.hasToOpenFile()) {
393394
this.viewlet.open(this.element, true);
394395
} else {

src/vs/workbench/parts/search/common/searchModel.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)