Skip to content

Commit 9b9508d

Browse files
committed
await on expand
Fixes microsoft#229878
1 parent d445ba0 commit 9b9508d

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ registerAction2(class RemoveAction extends Action2 {
126126

127127
if (focusElement && shouldRefocusMatch) {
128128
if (!nextFocusElement) {
129-
nextFocusElement = getLastNodeFromSameType(viewer, focusElement);
129+
nextFocusElement = await getLastNodeFromSameType(viewer, focusElement);
130130
}
131131

132132
if (nextFocusElement && !arrayContainsElementOrParent(nextFocusElement, elementsToRemove)) {
@@ -294,7 +294,7 @@ async function performReplace(accessor: ServicesAccessor,
294294

295295
if (focusElement) {
296296
if (!nextFocusElement) {
297-
nextFocusElement = getLastNodeFromSameType(viewer, focusElement);
297+
nextFocusElement = await getLastNodeFromSameType(viewer, focusElement);
298298
}
299299

300300
if (nextFocusElement) {
@@ -389,13 +389,16 @@ export function getElementToFocusAfterRemoved(viewer: WorkbenchCompressibleAsync
389389
/***
390390
* Finds the last element in the tree with the same type as `element`
391391
*/
392-
export function getLastNodeFromSameType(viewer: WorkbenchCompressibleAsyncDataTree<SearchResult, RenderableMatch>, element: RenderableMatch): RenderableMatch | undefined {
392+
export async function getLastNodeFromSameType(viewer: WorkbenchCompressibleAsyncDataTree<SearchResult, RenderableMatch>, element: RenderableMatch): Promise<RenderableMatch | undefined> {
393393
let lastElem: RenderableMatch | null = viewer.lastVisibleElement ?? null;
394394

395395
while (lastElem) {
396396
const compareVal = compareLevels(element, lastElem);
397397
if (compareVal === -1) {
398-
viewer.expand(lastElem);
398+
const expanded = await viewer.expand(lastElem);
399+
if (!expanded) {
400+
return lastElem;
401+
}
399402
lastElem = viewer.lastVisibleElement;
400403
} else if (compareVal === 1) {
401404
const potentialLastElem = viewer.getParentElement(lastElem);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,25 @@ suite('Search Actions', () => {
7575
assert.strictEqual(data[4], actual);
7676
});
7777

78-
test('Find last FileMatch in Tree', function () {
78+
test('Find last FileMatch in Tree', async function () {
7979
const fileMatch1 = aFileMatch();
8080
const fileMatch2 = aFileMatch();
8181
const fileMatch3 = aFileMatch();
8282
const data = [fileMatch1, aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), fileMatch3, aMatch(fileMatch3)];
8383
const tree = aTree(data);
8484

85-
const actual = getLastNodeFromSameType(tree, fileMatch1);
85+
const actual = await getLastNodeFromSameType(tree, fileMatch1);
8686
assert.strictEqual(fileMatch3, actual);
8787
});
8888

89-
test('Find last Match in Tree', function () {
89+
test('Find last Match in Tree', async function () {
9090
const fileMatch1 = aFileMatch();
9191
const fileMatch2 = aFileMatch();
9292
const fileMatch3 = aFileMatch();
9393
const data = [fileMatch1, aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), fileMatch3, aMatch(fileMatch3)];
9494
const tree = aTree(data);
9595

96-
const actual = getLastNodeFromSameType(tree, aMatch(fileMatch1));
96+
const actual = await getLastNodeFromSameType(tree, aMatch(fileMatch1));
9797
assert.strictEqual(data[5], actual);
9898
});
9999

0 commit comments

Comments
 (0)