Skip to content

Commit 0600b83

Browse files
committed
feat(amazonq): select chat history item on enter key press
1 parent ee75570 commit 0600b83

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

packages/core/src/amazonq/webview/ui/apps/baseConnector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface BaseConnectorProps {
3737
update: (data: DetailedList) => void
3838
close: () => void
3939
changeTarget: (direction: 'up' | 'down', snapOnLastAndFirst?: boolean) => void
40+
getTargetElementId: () => string | undefined
4041
}
4142
onSelectTab: (tabID: string, eventID: string) => void
4243
onExportChat: (tabId: string, format: 'html' | 'markdown') => string

packages/core/src/amazonq/webview/ui/connector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export interface ConnectorProps {
112112
update: (data: DetailedList) => void
113113
close: () => void
114114
changeTarget: (direction: 'up' | 'down', snapOnLastAndFirst?: boolean) => void
115+
getTargetElementId: () => string | undefined
115116
}
116117
onSelectTab: (tabID: string, eventID: string) => void
117118
onExportChat: (tabID: string, format: 'markdown' | 'html') => string

packages/core/src/amazonq/webview/ui/detailedList/detailedListConnector.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ export class DetailedListConnector {
1717
update: (data: DetailedList) => void
1818
close: () => void
1919
changeTarget: (direction: 'up' | 'down', snapOnLastAndFirst?: boolean) => void
20+
getTargetElementId: () => string | undefined
2021
}
2122
closeList() {}
2223
updateList(_data: DetailedList) {}
2324
changeTarget(_direction: 'up' | 'down', _snapOnLastAndFirst?: boolean) {}
25+
getTargetElementId(): string | undefined {
26+
return undefined
27+
}
2428

2529
constructor(
2630
type: DetailedListType,
@@ -29,6 +33,7 @@ export class DetailedListConnector {
2933
update: (data: DetailedList) => void
3034
close: () => void
3135
changeTarget: (direction: 'up' | 'down', snapOnLastAndFirst?: boolean) => void
36+
getTargetElementId: () => string | undefined
3237
}
3338
) {
3439
this.type = type
@@ -37,7 +42,7 @@ export class DetailedListConnector {
3742
}
3843

3944
openList(messageData: any) {
40-
const { update, close, changeTarget } = this.onOpenDetailedList({
45+
const { update, close, changeTarget, getTargetElementId } = this.onOpenDetailedList({
4146
tabId: messageData.tabID,
4247
detailedList: messageData.detailedList,
4348
events: {
@@ -50,6 +55,7 @@ export class DetailedListConnector {
5055
this.closeList = close
5156
this.updateList = update
5257
this.changeTarget = changeTarget
58+
this.getTargetElementId = getTargetElementId
5359
}
5460

5561
onFilterValueChange = (filterValues: Record<string, any>, isValid: boolean) => {
@@ -84,7 +90,12 @@ export class DetailedListConnector {
8490
if (e.key === 'Escape') {
8591
this.closeList()
8692
} else if (e.key === 'Enter') {
87-
// todo: call onItemSelect on Enter
93+
const targetElementId = this.getTargetElementId()
94+
if (targetElementId) {
95+
this.onItemSelect({
96+
id: targetElementId,
97+
})
98+
}
8899
} else if (e.key === 'ArrowUp') {
89100
this.changeTarget('up')
90101
} else if (e.key === 'ArrowDown') {

packages/core/src/amazonq/webview/ui/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,10 +966,12 @@ export const createMynahUI = (
966966
{
967967
id: 'history_sheet',
968968
icon: MynahIcons.COMMENT,
969+
description: 'View chat history',
969970
},
970971
{
971972
id: 'export_chat',
972973
icon: MynahIcons.EXTERNAL,
974+
description: 'Export chat',
973975
},
974976
],
975977
},

packages/core/src/shared/db/chatDb/chatDb.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class Database {
5252
autosave: true,
5353
autoload: true,
5454
autoloadCallback: () => this.databaseInitialize(),
55-
autosaveInterval: 4000,
55+
autosaveInterval: 1000,
5656
persistenceMethod: 'fs',
5757
})
5858
}
@@ -201,9 +201,6 @@ export class Database {
201201
return []
202202
}
203203

204-
/**
205-
* Returns DetailedListItemGroup[]
206-
*/
207204
getHistory(): DetailedListItemGroup[] {
208205
if (this.initialized) {
209206
const tabCollection = this.db.getCollection<Tab>(TabCollection)
@@ -217,6 +214,10 @@ export class Database {
217214
if (this.initialized) {
218215
const tabCollection = this.db.getCollection<Tab>(TabCollection)
219216
tabCollection.findAndRemove({ historyId })
217+
const tabId = this.getTabId(historyId)
218+
if (tabId) {
219+
this.historyIdMapping.delete(tabId)
220+
}
220221
}
221222
}
222223

0 commit comments

Comments
 (0)