Skip to content

Commit fc411d5

Browse files
committed
clean up
1 parent 3ed9e56 commit fc411d5

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

src/vs/workbench/contrib/chat/browser/chat.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ class ChatAccessibleViewContribution extends Disposable {
180180
},
181181
next() {
182182
verifiedWidget.focus(focusedItem);
183-
verifiedWidget.focusNext(focusedItem.id);
183+
verifiedWidget.focusWithId(focusedItem.id, 'next');
184184
renderAccessibleView(true, accessibleViewService, widgetService, codeEditorService);
185185
},
186186
previous() {
187187
verifiedWidget.focus(focusedItem);
188-
verifiedWidget.focusPrevious(focusedItem.id);
188+
verifiedWidget.focusWithId(focusedItem.id, 'previous');
189189
renderAccessibleView(true, accessibleViewService, widgetService, codeEditorService);
190190
},
191191
options: { ariaLabel: nls.localize('chatAccessibleView', "Chat Accessible View"), language: 'typescript', type: AccessibleViewType.View }

src/vs/workbench/contrib/chat/browser/chat.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ export interface IChatWidget {
5656

5757
reveal(item: ChatTreeItem): void;
5858
focus(item: ChatTreeItem): void;
59-
focusNext(id: string): void;
60-
focusPrevious(id: string): void;
59+
focusWithId(id: string, type: 'next' | 'previous'): void;
6160
getFocus(): ChatTreeItem | undefined;
6261
acceptInput(query?: string): void;
6362
focusLastMessage(): void;

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -168,44 +168,25 @@ export class ChatWidget extends Disposable implements IChatWidget {
168168
this.inputPart.focus();
169169
}
170170

171-
focusNext(id: string): void {
171+
focusWithId(id: string, type: 'next' | 'previous'): void {
172172
const items = this.viewModel?.getItems();
173173
if (!items) {
174174
return;
175175
}
176-
const focusedElement = items?.find(i => i.id === id) as any as IChatResponseViewModel;
177-
const responseItems = items?.filter(i => isResponseVM(i));
176+
const focusedElement = items.find(i => i.id === id);
178177
if (!focusedElement) {
179178
return;
180179
}
181-
const currentlyFocusedIndex = responseItems?.indexOf(focusedElement);
182-
if (currentlyFocusedIndex === undefined || !responseItems) {
183-
return;
184-
}
185-
if (currentlyFocusedIndex === responseItems.length - 1) {
186-
return;
187-
}
188-
this.focus(responseItems[currentlyFocusedIndex + 1], true);
189-
}
190-
191-
focusPrevious(id: string): void {
192-
const items = this.viewModel?.getItems();
193-
if (!items) {
194-
return;
195-
}
196-
const focusedElement = items.find(i => i.id === id) as any as IChatResponseViewModel;
197180
const responseItems = items.filter(i => isResponseVM(i));
198-
if (!focusedElement) {
199-
return;
200-
}
201181
const currentlyFocusedIndex = responseItems?.indexOf(focusedElement);
202-
if (!currentlyFocusedIndex || !responseItems) {
182+
if (currentlyFocusedIndex === undefined || !responseItems) {
203183
return;
204184
}
205-
if (currentlyFocusedIndex - 1 < 0) {
185+
const indexToFocus = type === 'next' ? currentlyFocusedIndex + 1 : currentlyFocusedIndex - 1;
186+
if (indexToFocus < 0 || indexToFocus === responseItems.length - 1) {
206187
return;
207188
}
208-
this.focus(responseItems[currentlyFocusedIndex - 1], true);
189+
this.focus(responseItems[indexToFocus]);
209190
}
210191

211192
private onDidChangeItems() {
@@ -427,17 +408,15 @@ export class ChatWidget extends Disposable implements IChatWidget {
427408
this.tree.reveal(item);
428409
}
429410

430-
focus(item: ChatTreeItem, noDomFocus?: boolean): void {
411+
focus(item: ChatTreeItem): void {
431412
const items = this.tree.getNode(null).children;
432413
const node = items.find(i => i.element?.id === item.id);
433414
if (!node) {
434415
return;
435416
}
436417

437418
this.tree.setFocus([node.element]);
438-
// if (!noDomFocus) {
439419
this.tree.domFocus();
440-
// }
441420
}
442421

443422
async acceptInput(query?: string | IChatReplyFollowup): Promise<void> {

0 commit comments

Comments
 (0)