1- import { useRef , useEffect , useMemo } from 'react'
1+ import { useRef , useEffect , useMemo , useState } from 'react'
22import styles from './ChatInput.module.scss'
33import TextareaAutosize from 'react-textarea-autosize'
44import cn from 'classnames'
55import { Icon } from '../../common/Icon'
66import { get_highlighted_text } from './utils/get-highlighted-text'
77import { use_handlers } from './hooks/use-handlers'
8+ import { use_dropdown } from './hooks/use-dropdown'
89
910export type EditFormat = 'whole' | 'truncated' | 'diff'
1011
@@ -40,7 +41,13 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
4041 const textarea_ref = useRef < HTMLTextAreaElement > ( null )
4142 const highlight_ref = useRef < HTMLDivElement > ( null )
4243 const container_ref = useRef < HTMLDivElement > ( null )
43-
44+ const {
45+ is_dropdown_open,
46+ toggle_dropdown,
47+ dropdown_ref,
48+ handle_copy_click,
49+ handle_select_click
50+ } = use_dropdown ( props )
4451 const {
4552 handle_select,
4653 handle_input_change,
@@ -49,6 +56,12 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
4956 is_history_enabled
5057 } = use_handlers ( props )
5158
59+ const is_mac = useMemo (
60+ ( ) => navigator . platform . toUpperCase ( ) . indexOf ( 'MAC' ) >= 0 ,
61+ [ ]
62+ )
63+ const mod_key = is_mac ? 'cmd' : 'ctrl'
64+
5265 useEffect ( ( ) => {
5366 if ( textarea_ref . current ) {
5467 textarea_ref . current . focus ( )
@@ -238,7 +251,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
238251 ] ] : props . edit_format == format
239252 }
240253 ) }
241- title = { props . edit_format_instructions ?. [ format ] }
254+ title = { `Attached edit format instructions: ${ props . edit_format_instructions ?. [ format ] } ` }
242255 onClick = { ( ) => props . on_edit_format_change ?.( format ) }
243256 data-text = { format }
244257 >
@@ -248,35 +261,86 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
248261 </ div >
249262 ) }
250263
251- { ( ! props . is_web_mode ||
252- ( props . is_web_mode && props . is_connected ) ) && (
253- < >
264+ < div className = { styles [ 'footer__right__submit' ] } ref = { dropdown_ref } >
265+ { ( ! props . is_web_mode ||
266+ ( props . is_web_mode && props . is_connected ) ) && (
267+ < >
268+ < button
269+ className = { cn (
270+ styles [ 'footer__right__submit__button' ] ,
271+ styles [ 'footer__right__submit__button--submit' ] ,
272+ 'codicon' ,
273+ 'codicon-send'
274+ ) }
275+ onClick = { handle_submit }
276+ title = { props . use_last_choice_button_title }
277+ />
278+ < button
279+ className = { cn (
280+ styles [ 'footer__right__submit__button' ] ,
281+ styles [ 'footer__right__submit__button--chevron' ] ,
282+ 'codicon' ,
283+ 'codicon-chevron-down'
284+ ) }
285+ onClick = { toggle_dropdown }
286+ title = "More actions"
287+ />
288+ { is_dropdown_open && (
289+ < div className = { styles [ 'footer__right__submit__dropdown' ] } >
290+ < div
291+ className = {
292+ styles [ 'footer__right__submit__dropdown__item' ]
293+ }
294+ onClick = { handle_select_click }
295+ >
296+ Select...
297+ < span
298+ className = {
299+ styles [
300+ 'footer__right__submit__dropdown__item__shortcut'
301+ ]
302+ }
303+ >
304+ { mod_key } +{ is_mac ? 'return' : 'enter' }
305+ </ span >
306+ </ div >
307+ < div
308+ className = {
309+ styles [ 'footer__right__submit__dropdown__item' ]
310+ }
311+ onClick = { handle_copy_click }
312+ >
313+ Copy
314+ < span
315+ className = {
316+ styles [
317+ 'footer__right__submit__dropdown__item__shortcut'
318+ ]
319+ }
320+ >
321+ { mod_key } +{ is_mac ? 'option' : 'alt' } +c
322+ </ span >
323+ </ div >
324+ </ div >
325+ ) }
326+ </ >
327+ ) }
328+
329+ { props . is_web_mode && ! props . is_connected && (
254330 < button
255331 className = { cn (
256- styles . footer__right__button ,
332+ styles [ 'footer__right__submit__button' ] ,
257333 'codicon' ,
258- 'codicon-send '
334+ 'codicon-copy '
259335 ) }
260- onClick = { handle_submit }
261- title = { props . use_last_choice_button_title }
336+ onClick = { ( e ) => {
337+ e . stopPropagation ( )
338+ props . on_copy ( )
339+ } }
340+ title = "Copy to clipboard"
262341 />
263- </ >
264- ) }
265-
266- { props . is_web_mode && ! props . is_connected && (
267- < button
268- className = { cn (
269- styles . footer__right__button ,
270- 'codicon' ,
271- 'codicon-copy'
272- ) }
273- onClick = { ( e ) => {
274- e . stopPropagation ( )
275- props . on_copy ( )
276- } }
277- title = "Copy to clipboard"
278- />
279- ) }
342+ ) }
343+ </ div >
280344 </ div >
281345 </ div >
282346 </ div >
0 commit comments