Skip to content

Commit 6926b1e

Browse files
committed
add up/down functionality while slash menu is active
1 parent 8091d1a commit 6926b1e

File tree

2 files changed

+31
-66
lines changed

2 files changed

+31
-66
lines changed

cli/src/chat.tsx

Lines changed: 31 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -297,62 +297,6 @@ export const Chat = ({
297297
localAgents,
298298
})
299299

300-
const [suggestionMenuDisabled, setSuggestionMenuDisabled] = useState(false)
301-
// Disable suggestion menu during navigation
302-
useEffect(() => {
303-
setSuggestionMenuDisabled(!lastEditDueToNav)
304-
}, [setSuggestionMenuDisabled, lastEditDueToNav])
305-
306-
const [historyNavUpEnabled, setHistoryNavUpEnabled] = useState(true)
307-
useEffect(() => {
308-
if (lastEditDueToNav) {
309-
setHistoryNavUpEnabled(true)
310-
return
311-
}
312-
313-
if (slashContext.active) {
314-
setHistoryNavUpEnabled(false)
315-
return
316-
}
317-
if (mentionContext.active) {
318-
setHistoryNavUpEnabled(false)
319-
return
320-
}
321-
322-
setHistoryNavUpEnabled(cursorPosition === 0)
323-
}, [
324-
setHistoryNavUpEnabled,
325-
lastEditDueToNav,
326-
slashContext.active,
327-
mentionContext.active,
328-
cursorPosition,
329-
])
330-
331-
const [historyNavDownEnabled, setHistoryNavDownEnabled] = useState(true)
332-
useEffect(() => {
333-
if (lastEditDueToNav) {
334-
setHistoryNavDownEnabled(true)
335-
return
336-
}
337-
338-
if (slashContext.active) {
339-
setHistoryNavDownEnabled(false)
340-
return
341-
}
342-
if (mentionContext.active) {
343-
setHistoryNavDownEnabled(false)
344-
return
345-
}
346-
347-
setHistoryNavDownEnabled(inputValue.length === cursorPosition)
348-
}, [
349-
setHistoryNavDownEnabled,
350-
lastEditDueToNav,
351-
slashContext.active,
352-
mentionContext.active,
353-
cursorPosition,
354-
inputValue.length,
355-
])
356300
useEffect(() => {
357301
if (!slashContext.active) {
358302
setSlashSelectedIndex(0)
@@ -422,15 +366,19 @@ export const Chat = ({
422366

423367
if (key.name === 'down' && !hasModifier) {
424368
// Move down (no wrap)
425-
setSlashSelectedIndex((prev) =>
426-
Math.min(prev + 1, slashMatches.length - 1),
427-
)
369+
if (slashSelectedIndex === slashMatches.length - 1) {
370+
return false
371+
}
372+
setSlashSelectedIndex((prev) => prev + 1)
428373
return true
429374
}
430375

431376
if (key.name === 'up' && !hasModifier) {
432377
// Move up (no wrap)
433-
setSlashSelectedIndex((prev) => Math.max(prev - 1, 0))
378+
if (slashSelectedIndex === 0) {
379+
return false
380+
}
381+
setSlashSelectedIndex((prev) => prev - 1)
434382
return true
435383
}
436384

@@ -506,15 +454,19 @@ export const Chat = ({
506454

507455
if (key.name === 'down' && !hasModifier) {
508456
// Move down (no wrap)
509-
setAgentSelectedIndex((prev) =>
510-
Math.min(prev + 1, agentMatches.length - 1),
511-
)
457+
if (agentSelectedIndex === agentMatches.length - 1) {
458+
return false
459+
}
460+
setAgentSelectedIndex((prev) => prev + 1)
512461
return true
513462
}
514463

515464
if (key.name === 'up' && !hasModifier) {
516465
// Move up (no wrap)
517-
setAgentSelectedIndex((prev) => Math.max(prev - 1, 0))
466+
if (agentSelectedIndex === 0) {
467+
return false
468+
}
469+
setAgentSelectedIndex((prev) => prev - 1)
518470
return true
519471
}
520472

@@ -709,6 +661,21 @@ export const Chat = ({
709661
],
710662
)
711663

664+
const historyNavUpEnabled =
665+
lastEditDueToNav ||
666+
(cursorPosition === 0 &&
667+
((slashContext.active && slashSelectedIndex === 0) ||
668+
(mentionContext.active && agentSelectedIndex === 0) ||
669+
(!slashContext.active && !mentionContext.active)))
670+
const historyNavDownEnabled =
671+
lastEditDueToNav ||
672+
(cursorPosition === inputValue.length &&
673+
((slashContext.active &&
674+
slashSelectedIndex === slashMatches.length - 1) ||
675+
(mentionContext.active &&
676+
agentSelectedIndex === agentMatches.length - 1) ||
677+
(!slashContext.active && !mentionContext.active)))
678+
712679
useKeyboardHandlers({
713680
isStreaming,
714681
isWaitingForResponse,

cli/src/components/multiline-input.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212

1313
import { useOpentuiPaste } from '../hooks/use-opentui-paste'
1414
import { useTheme } from '../hooks/use-theme'
15-
import { clamp } from '../utils/math'
1615
import { computeInputLayoutMetrics } from '../utils/text-layout'
1716

1817
import type { InputValue } from '../state/chat-store'
@@ -140,7 +139,6 @@ export const MultilineInput = forwardRef<
140139
[],
141140
)
142141

143-
144142
useOpentuiPaste(
145143
useCallback(
146144
(event: PasteEvent) => {

0 commit comments

Comments
 (0)