@@ -83,6 +83,54 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
8383 const [ is_text_selecting , set_is_text_selecting ] = useState ( false )
8484 const [ is_focused , set_is_focused ] = useState ( false )
8585
86+ const [ is_alt_pressed , set_is_alt_pressed ] = useState ( false )
87+
88+ useEffect ( ( ) => {
89+ const handle_key_down = ( e : KeyboardEvent ) => {
90+ if ( e . key == 'Alt' ) set_is_alt_pressed ( true )
91+
92+ if (
93+ e . altKey &&
94+ ! e . shiftKey &&
95+ ! e . ctrlKey &&
96+ ! e . metaKey &&
97+ props . show_edit_format_selector &&
98+ props . on_edit_format_change
99+ ) {
100+ let format : EditFormat | undefined
101+ switch ( e . code ) {
102+ case 'KeyW' :
103+ format = 'whole'
104+ break
105+ case 'KeyT' :
106+ format = 'truncated'
107+ break
108+ case 'KeyD' :
109+ format = 'diff'
110+ break
111+ }
112+ if ( format ) {
113+ e . preventDefault ( )
114+ props . on_edit_format_change ( format )
115+ }
116+ }
117+ }
118+ const handle_key_up = ( e : KeyboardEvent ) => {
119+ if ( e . key == 'Alt' ) set_is_alt_pressed ( false )
120+ }
121+ const handle_blur = ( ) => {
122+ set_is_alt_pressed ( false )
123+ }
124+ window . addEventListener ( 'keydown' , handle_key_down )
125+ window . addEventListener ( 'keyup' , handle_key_up )
126+ window . addEventListener ( 'blur' , handle_blur )
127+ return ( ) => {
128+ window . removeEventListener ( 'keydown' , handle_key_down )
129+ window . removeEventListener ( 'keyup' , handle_key_up )
130+ window . removeEventListener ( 'blur' , handle_blur )
131+ }
132+ } , [ props . show_edit_format_selector , props . on_edit_format_change ] )
133+
86134 const is_narrow_viewport = use_is_narrow_viewport ( 268 )
87135 const {
88136 is_dropdown_open,
@@ -146,10 +194,6 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
146194
147195 const is_mac = use_is_mac ( )
148196
149- const display_text = useMemo ( ( ) => {
150- return get_display_text ( props . value , props . context_file_paths ?? [ ] )
151- } , [ props . value , props . context_file_paths ] )
152-
153197 const highlighted_html = useMemo ( ( ) => {
154198 return get_highlighted_text ( {
155199 text : props . value ,
@@ -260,6 +304,15 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
260304 const has_no_context =
261305 ! props . context_file_paths || props . context_file_paths . length == 0
262306
307+ const edit_format_shortcuts : Record < EditFormat , string > = useMemo ( ( ) => {
308+ const modifier = is_mac ? '⌥' : 'Alt+'
309+ return {
310+ whole : `(${ modifier } W)` ,
311+ truncated : `(${ modifier } T)` ,
312+ diff : `(${ modifier } D)`
313+ }
314+ } , [ is_mac ] )
315+
263316 return (
264317 < div className = { styles . container } >
265318 { props . has_active_selection && props . is_in_code_completions_mode && (
@@ -417,6 +470,9 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
417470 const button_text = is_narrow_viewport
418471 ? format . charAt ( 0 ) . toUpperCase ( )
419472 : format
473+ const is_selected = props . edit_format == format
474+ const should_underline = is_alt_pressed && ! is_selected
475+
420476 return (
421477 < button
422478 key = { format }
@@ -425,14 +481,37 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
425481 {
426482 [ styles [
427483 'footer__right__edit-format__button--selected'
428- ] ] : props . edit_format == format
484+ ] ] : is_selected
429485 }
430486 ) }
431- title = { `${ props . edit_format_instructions ?. [ format ] } ` }
487+ title = { `Edit format instructions to include with the prompt ${ edit_format_shortcuts [ format ] } \n\n${
488+ props . edit_format_instructions ?. [ format ]
489+ } `}
432490 onClick = { ( ) => props . on_edit_format_change ?.( format ) }
433- data-text = { button_text }
434491 >
435- { button_text }
492+ < span
493+ className = {
494+ styles [ 'footer__right__edit-format__button__spacer' ]
495+ }
496+ >
497+ { button_text }
498+ </ span >
499+ < span
500+ className = {
501+ styles [ 'footer__right__edit-format__button__text' ]
502+ }
503+ >
504+ { should_underline ? (
505+ < >
506+ < span className = { styles [ 'underlined' ] } >
507+ { button_text . charAt ( 0 ) }
508+ </ span >
509+ { button_text . substring ( 1 ) }
510+ </ >
511+ ) : (
512+ button_text
513+ ) }
514+ </ span >
436515 </ button >
437516 )
438517 } ) }
0 commit comments