Skip to content

Commit

Permalink
explorer: Should maintain row focus after deleting a file
Browse files Browse the repository at this point in the history
fixes #71315
  • Loading branch information
isidorn committed Sep 11, 2020
1 parent 133d95e commit b0a913b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/vs/workbench/contrib/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ export class ExplorerView extends ViewPane {
return this.tree.updateChildren(toRefresh, recursive);
}

focusNextIfItemFocused(item: ExplorerItem): void {
const focus = this.tree.getFocus();
if (focus.length === 1 && focus[0] === item) {
this.tree.focusNext();
}
}

getOptimalWidth(): number {
const parentNode = this.tree.getHTMLElement();
const childNodes = ([] as HTMLElement[]).slice.call(parentNode.querySelectorAll('.explorer-item .label-name')); // select all file labels
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/files/common/explorerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export class ExplorerService implements IExplorerService {
const parent = element.parent;
// Remove Element from Parent (Model)
parent.removeChild(element);
this.view?.focusNextIfItemFocused(element);
// Refresh Parent (View)
await this.view?.refresh(false, parent);
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface IExplorerView {
setTreeInput(): Promise<void>;
itemsCopied(tats: ExplorerItem[], cut: boolean, previousCut: ExplorerItem[] | undefined): void;
setEditable(stat: ExplorerItem, isEditing: boolean): Promise<void>;
focusNextIfItemFocused(item: ExplorerItem): void;
}

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

0 comments on commit b0a913b

Please sign in to comment.