undo general focus/selection preservation from lists and trees (#201309)

fixes #174768
fixes #127622
This commit is contained in:
João Moreno 2023-12-20 16:28:45 +01:00 committed by GitHub
parent 199216cd48
commit d95f2e01ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 13 deletions

View file

@ -109,9 +109,8 @@ class TraitRenderer<T> implements IListRenderer<T, ITraitTemplateData>
class Trait<T> implements ISpliceable<boolean>, IDisposable {
private length = 0;
private indexes: number[] = [];
private sortedIndexes: number[] = [];
protected indexes: number[] = [];
protected sortedIndexes: number[] = [];
private readonly _onChange = new Emitter<ITraitChangeEvent>();
readonly onChange: Event<ITraitChangeEvent> = this._onChange.event;
@ -126,8 +125,6 @@ class Trait<T> implements ISpliceable<boolean>, IDisposable {
constructor(private _trait: string) { }
splice(start: number, deleteCount: number, elements: boolean[]): void {
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
const diff = elements.length - deleteCount;
const end = start + deleteCount;
const sortedIndexes: number[] = [];
@ -147,16 +144,8 @@ class Trait<T> implements ISpliceable<boolean>, IDisposable {
sortedIndexes.push(this.sortedIndexes[i++] + diff);
}
const length = this.length + diff;
if (this.sortedIndexes.length > 0 && sortedIndexes.length === 0 && length > 0) {
const first = this.sortedIndexes.find(index => index >= start) ?? length - 1;
sortedIndexes.push(Math.min(first, length - 1));
}
this.renderer.splice(start, deleteCount, elements.length);
this._set(sortedIndexes, sortedIndexes);
this.length = length;
}
renderIndex(index: number, container: HTMLElement): void {

View file

@ -448,6 +448,7 @@ export class ExplorerService implements IExplorerService {
// Remove Element from Parent (Model)
const parent = modelElement.parent;
parent.removeChild(modelElement);
this.view?.focusNext();
const oldNestedParent = modelElement.nestedParent;
if (oldNestedParent) {
@ -456,6 +457,10 @@ export class ExplorerService implements IExplorerService {
}
// Refresh Parent (View)
await this.view?.refresh(shouldDeepRefresh, parent);
if (this.view?.getFocus().length === 0) {
this.view?.focusLast();
}
}
}));
}

View file

@ -60,6 +60,9 @@ export interface IExplorerView {
isItemVisible(item: ExplorerItem): boolean;
isItemCollapsed(item: ExplorerItem): boolean;
hasFocus(): boolean;
getFocus(): ExplorerItem[];
focusNext(): void;
focusLast(): void;
}
function getFocus(listService: IListService): unknown | undefined {

View file

@ -348,6 +348,18 @@ export class ExplorerView extends ViewPane implements IExplorerView {
return DOM.isAncestorOfActiveElement(this.container);
}
getFocus(): ExplorerItem[] {
return this.tree.getFocus();
}
focusNext(): void {
this.tree.focusNext();
}
focusLast(): void {
this.tree.focusLast();
}
getContext(respectMultiSelection: boolean): ExplorerItem[] {
return getContext(this.tree.getFocus(), this.tree.getSelection(), respectMultiSelection, this.renderer);
}

View file

@ -155,6 +155,11 @@ class WorkspaceTrustedUrisTable extends Disposable {
return localize('trustedFolderWithHostAriaLabel', "{0} on {1}, trusted", this.labelService.getUriLabel(item.uri), hostLabel);
},
getWidgetAriaLabel: () => localize('trustedFoldersAndWorkspaces', "Trusted Folders & Workspaces")
},
identityProvider: {
getId(element: ITrustedUriItem) {
return element.uri.toString();
},
}
}
) as WorkbenchTable<ITrustedUriItem>;
@ -336,8 +341,14 @@ class WorkspaceTrustedUrisTable extends Disposable {
}
async delete(item: ITrustedUriItem) {
this.table.focusNext();
await this.workspaceTrustManagementService.setUrisTrust([item.uri], false);
if (this.table.getFocus().length === 0) {
this.table.focusLast();
}
this._onDelete.fire(item);
this.table.domFocus();
}
async edit(item: ITrustedUriItem, usePickerIfPossible?: boolean) {