Skip to content

Commit 052c389

Browse files
authored
Merge pull request #96803 from microsoft/roblou/fix91901
Distinguish a user removing a row from 'clear' in search
2 parents 69eb032 + d07ffbc commit 052c389

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
615615
this.viewer.setFocus([nextFocusElement], getSelectionKeyboardEvent());
616616
}
617617

618-
this.element.parent().remove(<any>this.element);
618+
this.element.parent().remove(<any>this.element, true);
619619
this.viewer.domFocus();
620620

621621
return Promise.resolve();

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ export class FileMatch extends Disposable implements IFileMatch {
192192
return (selected ? FileMatch._CURRENT_FIND_MATCH : FileMatch._FIND_MATCH);
193193
}
194194

195-
private _onChange = this._register(new Emitter<{ didRemove?: boolean; forceUpdateModel?: boolean }>());
196-
readonly onChange: Event<{ didRemove?: boolean; forceUpdateModel?: boolean }> = this._onChange.event;
195+
private _onChange = this._register(new Emitter<{ didRemove?: boolean; forceUpdateModel?: boolean; userRemoved?: boolean }>());
196+
readonly onChange: Event<{ didRemove?: boolean; forceUpdateModel?: boolean; userRemoved?: boolean }> = this._onChange.event;
197197

198198
private _onDispose = this._register(new Emitter<void>());
199199
readonly onDispose: Event<void> = this._onDispose.event;
@@ -354,10 +354,10 @@ export class FileMatch extends Disposable implements IFileMatch {
354354
return values(this._matches);
355355
}
356356

357-
remove(match: Match): void {
357+
remove(match: Match, userRemoved?: boolean): void {
358358
this.removeMatch(match);
359359
this._removedMatches.add(match.id());
360-
this._onChange.fire({ didRemove: true });
360+
this._onChange.fire({ didRemove: true, userRemoved });
361361
}
362362

363363
replace(toReplace: Match): Promise<void> {
@@ -447,6 +447,7 @@ export interface IChangeEvent {
447447
elements: FileMatch[];
448448
added?: boolean;
449449
removed?: boolean;
450+
userRemoved?: boolean;
450451
}
451452

452453
export class FolderMatch extends Disposable {
@@ -529,7 +530,7 @@ export class FolderMatch extends Disposable {
529530
const fileMatch = this.instantiationService.createInstance(FileMatch, this._query.contentPattern, this._query.previewOptions, this._query.maxResults, this, rawFileMatch);
530531
this.doAdd(fileMatch);
531532
added.push(fileMatch);
532-
const disposable = fileMatch.onChange(({ didRemove }) => this.onFileChange(fileMatch, didRemove));
533+
const disposable = fileMatch.onChange(({ didRemove, userRemoved }) => this.onFileChange(fileMatch, didRemove, userRemoved));
533534
fileMatch.onDispose(() => disposable.dispose());
534535
}
535536
});
@@ -540,14 +541,14 @@ export class FolderMatch extends Disposable {
540541
}
541542
}
542543

543-
clear(): void {
544+
clear(userRemoved?: boolean): void {
544545
const changed: FileMatch[] = this.matches();
545546
this.disposeMatches();
546-
this._onChange.fire({ elements: changed, removed: true });
547+
this._onChange.fire({ elements: changed, removed: true, userRemoved });
547548
}
548549

549-
remove(matches: FileMatch | FileMatch[]): void {
550-
this.doRemove(matches);
550+
remove(matches: FileMatch | FileMatch[], userRemoved?: boolean): void {
551+
this.doRemove(matches, undefined, undefined, userRemoved);
551552
}
552553

553554
replace(match: FileMatch): Promise<any> {
@@ -577,7 +578,7 @@ export class FolderMatch extends Disposable {
577578
return this.matches().reduce<number>((prev, match) => prev + match.count(), 0);
578579
}
579580

580-
private onFileChange(fileMatch: FileMatch, removed = false): void {
581+
private onFileChange(fileMatch: FileMatch, removed = false, userRemoved = false): void {
581582
let added = false;
582583
if (!this._fileMatches.has(fileMatch.resource)) {
583584
this.doAdd(fileMatch);
@@ -589,7 +590,7 @@ export class FolderMatch extends Disposable {
589590
removed = true;
590591
}
591592
if (!this._replacingAll) {
592-
this._onChange.fire({ elements: [fileMatch], added: added, removed: removed });
593+
this._onChange.fire({ elements: [fileMatch], added: added, removed: removed, userRemoved });
593594
}
594595
}
595596

@@ -600,7 +601,7 @@ export class FolderMatch extends Disposable {
600601
}
601602
}
602603

603-
private doRemove(fileMatches: FileMatch | FileMatch[], dispose: boolean = true, trigger: boolean = true): void {
604+
private doRemove(fileMatches: FileMatch | FileMatch[], dispose: boolean = true, trigger: boolean = true, userRemoved: boolean = false): void {
604605
if (!Array.isArray(fileMatches)) {
605606
fileMatches = [fileMatches];
606607
}
@@ -615,7 +616,7 @@ export class FolderMatch extends Disposable {
615616
}
616617

617618
if (trigger) {
618-
this._onChange.fire({ elements: fileMatches, removed: true });
619+
this._onChange.fire({ elements: fileMatches, removed: true, userRemoved });
619620
}
620621
}
621622

@@ -717,7 +718,7 @@ export class SearchResult extends Disposable {
717718
this._register(this.modelService.onModelAdded(model => this.onModelAdded(model)));
718719

719720
this._register(this.onChange(e => {
720-
if (e.removed) {
721+
if (e.userRemoved) {
721722
this._hasRemovedResults = true;
722723
}
723724
}));
@@ -808,14 +809,14 @@ export class SearchResult extends Disposable {
808809
this._otherFilesMatch = null;
809810
}
810811

811-
remove(matches: FileMatch | FolderMatch | (FileMatch | FolderMatch)[]): void {
812+
remove(matches: FileMatch | FolderMatch | (FileMatch | FolderMatch)[], userRemoved?: boolean): void {
812813
if (!Array.isArray(matches)) {
813814
matches = [matches];
814815
}
815816

816817
matches.forEach(m => {
817818
if (m instanceof FolderMatch) {
818-
m.clear();
819+
m.clear(userRemoved);
819820
}
820821
});
821822

@@ -827,11 +828,11 @@ export class SearchResult extends Disposable {
827828
return;
828829
}
829830

830-
this.getFolderMatch(matches[0].resource).remove(<FileMatch[]>matches);
831+
this.getFolderMatch(matches[0].resource).remove(<FileMatch[]>matches, userRemoved);
831832
});
832833

833834
if (other.length) {
834-
this.getFolderMatch(other[0].resource).remove(<FileMatch[]>other);
835+
this.getFolderMatch(other[0].resource).remove(<FileMatch[]>other, userRemoved);
835836
}
836837
}
837838

src/vs/workbench/contrib/search/test/common/searchResult.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ suite('SearchResult', () => {
236236
testObject.remove(objectToRemove);
237237

238238
assert.ok(target.calledOnce);
239-
assert.deepEqual([{ elements: [objectToRemove], removed: true }], target.args[0]);
239+
assert.deepEqual([{ elements: [objectToRemove], removed: true, userRemoved: false }], target.args[0]);
240240
});
241241

242242
test('remove array triggers change event', function () {
@@ -253,7 +253,7 @@ suite('SearchResult', () => {
253253
testObject.remove(arrayToRemove);
254254

255255
assert.ok(target.calledOnce);
256-
assert.deepEqual([{ elements: arrayToRemove, removed: true }], target.args[0]);
256+
assert.deepEqual([{ elements: arrayToRemove, removed: true, userRemoved: false }], target.args[0]);
257257
});
258258

259259
test('remove triggers change event', function () {
@@ -268,7 +268,7 @@ suite('SearchResult', () => {
268268
testObject.remove(objectToRemove);
269269

270270
assert.ok(target.calledOnce);
271-
assert.deepEqual([{ elements: [objectToRemove], removed: true }], target.args[0]);
271+
assert.deepEqual([{ elements: [objectToRemove], removed: true, userRemoved: false }], target.args[0]);
272272
});
273273

274274
test('Removing all line matches and adding back will add file back to result', function () {
@@ -315,7 +315,7 @@ suite('SearchResult', () => {
315315

316316
return voidPromise.then(() => {
317317
assert.ok(target.calledOnce);
318-
assert.deepEqual([{ elements: [objectToRemove], removed: true }], target.args[0]);
318+
assert.deepEqual([{ elements: [objectToRemove], removed: true, userRemoved: false }], target.args[0]);
319319
});
320320
});
321321

0 commit comments

Comments
 (0)