|
1 | 1 | import { useCallback, useEffect, useMemo, useRef, useState } from 'react' |
2 | 2 | import { useShallow } from 'zustand/react/shallow' |
3 | 3 |
|
4 | | -import type { ContentBlock } from './types/chat' |
5 | | - |
6 | 4 | import { routeUserPrompt } from './commands/router' |
7 | 5 | import { AgentModeToggle } from './components/agent-mode-toggle' |
8 | 6 | import { BuildModeButtons } from './components/build-mode-buttons' |
@@ -39,6 +37,7 @@ import { createMarkdownPalette } from './utils/theme-system' |
39 | 37 | import { BORDER_CHARS } from './utils/ui-constants' |
40 | 38 |
|
41 | 39 | import type { SendMessageTimerEvent } from './hooks/use-send-message' |
| 40 | +import type { ContentBlock } from './types/chat' |
42 | 41 | import type { SendMessageFn } from './types/contracts/send-message' |
43 | 42 | import type { ScrollBoxRenderable } from '@opentui/core' |
44 | 43 |
|
@@ -303,31 +302,56 @@ export const Chat = ({ |
303 | 302 | setSuggestionMenuDisabled(!lastEditDueToNav) |
304 | 303 | }, [setSuggestionMenuDisabled, lastEditDueToNav]) |
305 | 304 |
|
306 | | - // Disable history navigation during suggesion menu |
307 | | - const [historyNavEnabled, setHistoryNavEnabled] = useState(true) |
| 305 | + const [historyNavUpEnabled, setHistoryNavUpEnabled] = useState(true) |
308 | 306 | useEffect(() => { |
309 | 307 | if (lastEditDueToNav) { |
310 | | - setHistoryNavEnabled(true) |
| 308 | + setHistoryNavUpEnabled(true) |
311 | 309 | return |
312 | 310 | } |
313 | 311 |
|
314 | 312 | if (slashContext.active) { |
315 | | - setHistoryNavEnabled(false) |
| 313 | + setHistoryNavUpEnabled(false) |
316 | 314 | return |
317 | 315 | } |
318 | 316 | if (mentionContext.active) { |
319 | | - setHistoryNavEnabled(false) |
| 317 | + setHistoryNavUpEnabled(false) |
320 | 318 | return |
321 | 319 | } |
322 | 320 |
|
323 | | - setHistoryNavEnabled(true) |
| 321 | + setHistoryNavUpEnabled(cursorPosition === 0) |
324 | 322 | }, [ |
325 | | - setHistoryNavEnabled, |
| 323 | + setHistoryNavUpEnabled, |
326 | 324 | lastEditDueToNav, |
327 | 325 | slashContext.active, |
328 | 326 | mentionContext.active, |
| 327 | + cursorPosition, |
329 | 328 | ]) |
330 | 329 |
|
| 330 | + const [historyNavDownEnabled, setHistoryNavDownEnabled] = useState(true) |
| 331 | + useEffect(() => { |
| 332 | + if (lastEditDueToNav) { |
| 333 | + setHistoryNavDownEnabled(true) |
| 334 | + return |
| 335 | + } |
| 336 | + |
| 337 | + if (slashContext.active) { |
| 338 | + setHistoryNavDownEnabled(false) |
| 339 | + return |
| 340 | + } |
| 341 | + if (mentionContext.active) { |
| 342 | + setHistoryNavDownEnabled(false) |
| 343 | + return |
| 344 | + } |
| 345 | + |
| 346 | + setHistoryNavDownEnabled(inputValue.length === cursorPosition) |
| 347 | + }, [ |
| 348 | + setHistoryNavDownEnabled, |
| 349 | + lastEditDueToNav, |
| 350 | + slashContext.active, |
| 351 | + mentionContext.active, |
| 352 | + cursorPosition, |
| 353 | + inputValue.length, |
| 354 | + ]) |
331 | 355 | useEffect(() => { |
332 | 356 | if (!slashContext.active) { |
333 | 357 | setSlashSelectedIndex(0) |
@@ -711,7 +735,8 @@ export const Chat = ({ |
711 | 735 | navigateDown, |
712 | 736 | toggleAgentMode, |
713 | 737 | onCtrlC: handleCtrlC, |
714 | | - historyNavEnabled, |
| 738 | + historyNavUpEnabled, |
| 739 | + historyNavDownEnabled, |
715 | 740 | }) |
716 | 741 |
|
717 | 742 | const { tree: messageTree, topLevelMessages } = useMemo( |
|
0 commit comments