Skip to content

Commit b0a913b

Browse files
committed
explorer: Should maintain row focus after deleting a file
fixes #71315
1 parent 133d95e commit b0a913b

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/vs/workbench/contrib/files/browser/views/explorerView.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,13 @@ export class ExplorerView extends ViewPane {
588588
return this.tree.updateChildren(toRefresh, recursive);
589589
}
590590

591+
focusNextIfItemFocused(item: ExplorerItem): void {
592+
const focus = this.tree.getFocus();
593+
if (focus.length === 1 && focus[0] === item) {
594+
this.tree.focusNext();
595+
}
596+
}
597+
591598
getOptimalWidth(): number {
592599
const parentNode = this.tree.getHTMLElement();
593600
const childNodes = ([] as HTMLElement[]).slice.call(parentNode.querySelectorAll('.explorer-item .label-name')); // select all file labels

src/vs/workbench/contrib/files/common/explorerService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export class ExplorerService implements IExplorerService {
278278
const parent = element.parent;
279279
// Remove Element from Parent (Model)
280280
parent.removeChild(element);
281+
this.view?.focusNextIfItemFocused(element);
281282
// Refresh Parent (View)
282283
await this.view?.refresh(false, parent);
283284
}

src/vs/workbench/contrib/files/common/files.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface IExplorerView {
6565
setTreeInput(): Promise<void>;
6666
itemsCopied(tats: ExplorerItem[], cut: boolean, previousCut: ExplorerItem[] | undefined): void;
6767
setEditable(stat: ExplorerItem, isEditing: boolean): Promise<void>;
68+
focusNextIfItemFocused(item: ExplorerItem): void;
6869
}
6970

7071
export const IExplorerService = createDecorator<IExplorerService>('explorerService');

0 commit comments

Comments
 (0)