@@ -389,12 +389,6 @@ export const Chat = ({
389389 const handleSlashMenuKey = useCallback (
390390 (
391391 key : any ,
392- helpers : {
393- value : string
394- cursorPosition : number
395- setValue : ( newValue : string ) => number
396- setCursorPosition : ( position : number ) => void
397- } ,
398392 ) : boolean => {
399393 if ( ! slashContext . active || slashMatches . length === 0 ) {
400394 return false
@@ -411,15 +405,14 @@ export const Chat = ({
411405 if ( startIndex < 0 ) {
412406 return false
413407 }
414- const before = helpers . value . slice ( 0 , startIndex )
415- const after = helpers . value . slice (
408+ const before = inputValue . slice ( 0 , startIndex )
409+ const after = inputValue . slice (
416410 startIndex + 1 + slashContext . query . length ,
417- helpers . value . length ,
411+ inputValue . length ,
418412 )
419413 const replacement = `/${ selected . id } `
420414 const newValue = before + replacement + after
421- helpers . setValue ( newValue )
422- helpers . setCursorPosition ( before . length + replacement . length )
415+ setInputValue ( { text : newValue , cursorPosition : before . length + replacement . length , lastEditDueToNav : false } )
423416 setSlashSelectedIndex ( 0 )
424417 return true
425418 }
@@ -469,18 +462,14 @@ export const Chat = ({
469462 slashContext . query ,
470463 slashMatches ,
471464 slashSelectedIndex ,
465+ inputValue ,
466+ setInputValue ,
472467 ] ,
473468 )
474469
475470 const handleAgentMenuKey = useCallback (
476471 (
477472 key : any ,
478- helpers : {
479- value : string
480- cursorPosition : number
481- setValue : ( newValue : string ) => number
482- setCursorPosition : ( position : number ) => void
483- } ,
484473 ) : boolean => {
485474 if ( ! mentionContext . active || agentMatches . length === 0 ) {
486475 return false
@@ -498,15 +487,17 @@ export const Chat = ({
498487 return false
499488 }
500489
501- const before = helpers . value . slice ( 0 , startIndex )
502- const after = helpers . value . slice (
490+ const before = inputValue . slice ( 0 , startIndex )
491+ const after = inputValue . slice (
503492 startIndex + 1 + mentionContext . query . length ,
504- helpers . value . length ,
493+ inputValue . length ,
505494 )
506495 const replacement = `@${ selected . displayName } `
507496 const newValue = before + replacement + after
508- helpers . setValue ( newValue )
509- helpers . setCursorPosition ( before . length + replacement . length )
497+ setInputValue ( { text : newValue ,
498+ cursorPosition : before . length + replacement . length ,
499+ lastEditDueToNav : false ,
500+ } )
510501 setAgentSelectedIndex ( 0 )
511502 return true
512503 }
@@ -556,24 +547,20 @@ export const Chat = ({
556547 mentionContext . query ,
557548 agentMatches ,
558549 agentSelectedIndex ,
550+ inputValue ,
551+ setInputValue ,
559552 ] ,
560553 )
561554
562555 const handleSuggestionMenuKey = useCallback (
563556 (
564557 key : any ,
565- helpers : {
566- value : string
567- cursorPosition : number
568- setValue : ( newValue : string ) => number
569- setCursorPosition : ( position : number ) => void
570- } ,
571558 ) : boolean => {
572- if ( handleSlashMenuKey ( key , helpers ) ) {
559+ if ( handleSlashMenuKey ( key ) ) {
573560 return true
574561 }
575562
576- if ( handleAgentMenuKey ( key , helpers ) ) {
563+ if ( handleAgentMenuKey ( key ) ) {
577564 return true
578565 }
579566
0 commit comments