|
1 | | -import { useRef, useEffect, useMemo, useState } from 'react' |
| 1 | +import { useRef, useEffect, useMemo } from 'react' |
2 | 2 | import styles from './ChatInput.module.scss' |
3 | 3 | import TextareaAutosize from 'react-textarea-autosize' |
4 | 4 | import cn from 'classnames' |
5 | 5 | import { Icon } from '../../common/Icon' |
6 | 6 | import { get_highlighted_text } from './utils/get-highlighted-text' |
7 | 7 | import { use_handlers } from './hooks/use-handlers' |
8 | 8 | import { use_dropdown } from './hooks/use-dropdown' |
| 9 | +import { DropdownMenu } from '../../common/DropdownMenu' |
9 | 10 |
|
10 | 11 | export type EditFormat = 'whole' | 'truncated' | 'diff' |
11 | 12 |
|
@@ -57,10 +58,18 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => { |
57 | 58 | is_history_enabled |
58 | 59 | } = use_handlers(props) |
59 | 60 |
|
60 | | - const is_mac = useMemo( |
61 | | - () => navigator.platform.toUpperCase().indexOf('MAC') >= 0, |
62 | | - [] |
63 | | - ) |
| 61 | + const is_mac = useMemo(() => { |
| 62 | + if (typeof navigator == 'undefined') return false |
| 63 | + const any_nav = navigator as any |
| 64 | + const uach_platform: string | undefined = any_nav?.userAgentData?.platform |
| 65 | + if (typeof uach_platform == 'string') { |
| 66 | + return uach_platform.toLowerCase().includes('mac') |
| 67 | + } |
| 68 | + if (typeof navigator.userAgent == 'string') { |
| 69 | + return /mac/i.test(navigator.userAgent) |
| 70 | + } |
| 71 | + return false |
| 72 | + }, []) |
64 | 73 | const mod_key = is_mac ? 'cmd' : 'ctrl' |
65 | 74 |
|
66 | 75 | useEffect(() => { |
@@ -109,8 +118,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => { |
109 | 118 | }, [ |
110 | 119 | props.is_in_code_completions_mode, |
111 | 120 | props.chat_history, |
112 | | - is_history_enabled, |
113 | | - props.is_web_mode |
| 121 | + is_history_enabled |
114 | 122 | ]) |
115 | 123 |
|
116 | 124 | const custom_handle_key_down = ( |
@@ -306,42 +314,20 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => { |
306 | 314 | /> |
307 | 315 | </button> |
308 | 316 | {is_dropdown_open && ( |
309 | | - <div className={styles['footer__right__submit__dropdown']}> |
310 | | - <div |
311 | | - className={ |
312 | | - styles['footer__right__submit__dropdown__item'] |
313 | | - } |
314 | | - onClick={handle_select_click} |
315 | | - > |
316 | | - Select... |
317 | | - <span |
318 | | - className={ |
319 | | - styles[ |
320 | | - 'footer__right__submit__dropdown__item__shortcut' |
321 | | - ] |
322 | | - } |
323 | | - > |
324 | | - {mod_key}+{is_mac ? 'return' : 'enter'} |
325 | | - </span> |
326 | | - </div> |
327 | | - <div |
328 | | - className={ |
329 | | - styles['footer__right__submit__dropdown__item'] |
| 317 | + <DropdownMenu |
| 318 | + items={[ |
| 319 | + { |
| 320 | + label: 'Select...', |
| 321 | + shortcut: `${mod_key}+${is_mac ? 'return' : 'enter'}`, |
| 322 | + on_click: handle_select_click |
| 323 | + }, |
| 324 | + { |
| 325 | + label: 'Copy prompt', |
| 326 | + shortcut: `${mod_key}+${is_mac ? 'option' : 'alt'}+c`, |
| 327 | + on_click: handle_copy_click |
330 | 328 | } |
331 | | - onClick={handle_copy_click} |
332 | | - > |
333 | | - Copy prompt |
334 | | - <span |
335 | | - className={ |
336 | | - styles[ |
337 | | - 'footer__right__submit__dropdown__item__shortcut' |
338 | | - ] |
339 | | - } |
340 | | - > |
341 | | - {mod_key}+{is_mac ? 'option' : 'alt'}+c |
342 | | - </span> |
343 | | - </div> |
344 | | - </div> |
| 329 | + ]} |
| 330 | + /> |
345 | 331 | )} |
346 | 332 | </> |
347 | 333 | )} |
|
0 commit comments