Skip to content

Commit 8c60935

Browse files
authored
feat: call onSearchShortcut on ctrl/cmd + f (#396)
1 parent 2230229 commit 8c60935

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

docs/CONFIG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ interface ConfigModel {
5656
maxTabs: number; // set 1 to hide tabs panel
5757
showPromptField: boolean; // shows prompt field (default: true)
5858
dragOverlayIcon?: MynahIcons | MynahIconsType | CustomIcon; // icon displayed in the overlay when a file is dragged into the chat area
59+
enableSearchKeyboardShortcut?: boolean; // if true, calls onSearchShortcut on Command + f or Ctrl + f (default: false)
5960
}
6061
...
6162
```
@@ -405,4 +406,12 @@ Specifies the icon to display in the drag-and-drop overlay for adding files (suc
405406

406407
<p align="center">
407408
<img src="./img/dragOverlayIcon.png" alt="noPrompt" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;">
408-
</p>
409+
</p>
410+
411+
## enableSearchKeyboardShortcut
412+
413+
**Type:** `boolean`
414+
415+
When set to `true`, this option enables capturing the search keyboard shortcut. When enabled, pressing Command+F (Mac) or Ctrl+F (Windows/Linux) will trigger the `onSearchShortcut` event instead of the browser's default search behavior. This allows implementing custom search functionality within the chat interface.
416+
417+
Default: `false`

docs/PROPERTIES.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,3 +1296,23 @@ onFilesDropped: (tabId, files, insertPosition) => {
12961296
```
12971297

12981298
---
1299+
1300+
### `onSearchShortcut`
1301+
1302+
This event will be fired when the user presses Command+F (Mac) or Ctrl+F (Windows/Linux). It passes the `tabId` of the current tab and the `eventId` for tracking user intent. This allows the consumer to implement custom search functionality when the standard browser search shortcut is pressed.
1303+
1304+
```typescript
1305+
...
1306+
onSearchShortcut?: (
1307+
tabId: string,
1308+
eventId?: string) => void;
1309+
...
1310+
```
1311+
1312+
**Example:**
1313+
```typescript
1314+
onSearchShortcut: (tabId, eventId) => {
1315+
console.log(`Search shortcut triggered in tab: ${tabId}`);
1316+
// Implement custom search functionality, such as opening a history sheet
1317+
},
1318+
```

example/src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,9 @@ here to see if it gets cut off properly as expected, with an ellipsis through cs
10371037
onTabAdd: (tabId: string) => {
10381038
Log(`New tab added: <b>${tabId}</b>`);
10391039
},
1040+
onSearchShortcut: (tabId: string) => {
1041+
Log(`Search shortcut pressed on tab: <b>${tabId}</b>`);
1042+
},
10401043
onOpenFileDialogClick: (tabId: string, fileType: string, insertPosition: number) => {
10411044

10421045
if (fileType === 'image') {

src/main.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
TreeNodeDetails,
3232
Action,
3333
} from './static';
34-
import { MynahUIGlobalEvents } from './helper/events';
34+
import { cancelEvent, MynahUIGlobalEvents } from './helper/events';
3535
import { Tabs } from './components/navigation-tabs';
3636
import { ChatWrapper } from './components/chat-item/chat-wrapper';
3737
import { FeedbackForm } from './components/feedback-form/feedback-form';
@@ -167,6 +167,9 @@ export interface MynahUIProps {
167167
onTabRemove?: (
168168
tabId: string,
169169
eventId?: string) => void;
170+
onSearchShortcut?: (
171+
tabId: string,
172+
eventId?: string) => void;
170173
/**
171174
* @param tabId tabId which the close button triggered
172175
* @returns boolean -> If you want to close the tab immediately send true
@@ -480,6 +483,20 @@ export class MynahUI {
480483
if (this.props.onReady !== undefined) {
481484
this.props.onReady();
482485
}
486+
if (Config.getInstance().config.enableSearchKeyboardShortcut === true) {
487+
document.addEventListener('keydown', (e) => {
488+
// Check for Command+F (Mac) or Ctrl+F (Windows/Linux)
489+
if ((e.metaKey || e.ctrlKey) && e.key === 'f') {
490+
cancelEvent(e);
491+
// Call the search shortcut handler with the current tab ID
492+
if (this.props.onSearchShortcut !== undefined) {
493+
this.props.onSearchShortcut(
494+
MynahUITabsStore.getInstance().getSelectedTabId(),
495+
this.getUserEventId());
496+
}
497+
}
498+
});
499+
}
483500
}
484501

485502
private readonly getSplashLoaderActions = (actions?: Action[]): ExtendedHTMLElement[] => {

src/static.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ export interface ConfigOptions {
792792
codeCopyToClipboardEnabled?: boolean;
793793
test?: boolean;
794794
dragOverlayIcon?: MynahIcons | MynahIconsType | CustomIcon;
795+
enableSearchKeyboardShortcut?: boolean;
795796
}
796797

797798
export interface ConfigModel extends ConfigOptions {

0 commit comments

Comments
 (0)