Skip to content

Commit 2130977

Browse files
committed
remove helpers object
1 parent 1d1959b commit 2130977

File tree

2 files changed

+19
-53
lines changed

2 files changed

+19
-53
lines changed

cli/src/chat.tsx

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

cli/src/components/multiline-input.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,7 @@ interface MultilineInputProps {
8383
value: string
8484
onChange: (value: InputValue | ((prev: InputValue) => InputValue)) => void
8585
onSubmit: () => void
86-
onKeyIntercept?: (
87-
key: any,
88-
helpers: {
89-
value: string
90-
cursorPosition: number
91-
setValue: (newValue: string) => number
92-
setCursorPosition: (position: number) => void
93-
},
94-
) => boolean
86+
onKeyIntercept?: (key: any) => boolean
9587
placeholder?: string
9688
focused?: boolean
9789
maxHeight?: number
@@ -208,20 +200,7 @@ export const MultilineInput = forwardRef<
208200
if (!focused) return
209201

210202
if (onKeyIntercept) {
211-
const handled = onKeyIntercept(key, {
212-
value,
213-
cursorPosition,
214-
setValue: (newValue: string) => {
215-
onChange({
216-
text: newValue,
217-
cursorPosition,
218-
lastEditDueToNav: false,
219-
})
220-
return newValue.length
221-
},
222-
setCursorPosition: (position: number) =>
223-
setCursorPosition(Math.max(0, position)),
224-
})
203+
const handled = onKeyIntercept(key)
225204
if (handled) {
226205
return
227206
}

0 commit comments

Comments
 (0)