From 74fa09225a9c1d3a9ec44825bb26f56f9e98123a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ng=C3=B4=20Th=C6=B0=E1=BB=A3ng?= <83950837+nguyenngothuong@users.noreply.github.com> Date: Mon, 23 Feb 2026 05:04:25 +0700 Subject: [PATCH] feat(chat): per-session draft persistence + expandable input focus mode (#480) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(session-folders): drag-to-folder DnD, sort by activity, and UX improvements - Add DraggableSessionRow wrapping each session row so the whole row is draggable; stopPropagation prevents outer group-reorder DnD from firing - Add DroppableFolderWrapper + SessionFolderDndScope (inner DndContext scoped per group) with closestCenter collision detection - DragOverlay matches exact width/height of dragged row so cursor stays aligned - Folder header highlights (ring + primary colour) when a session hovers over it during drag - + button on folder header opens a dropdown: 'New session' / 'New folder' - + button on each folder row creates a session scoped to that folder - Empty folders are no longer auto-deleted (removed .filter(sessionIds.length>0) from addSessionToFolder / removeSessionFromFolder / cleanupSessions) - Sessions inside a folder are sorted by most-recent activity (same compareSessionsByPinnedAndTime logic used everywhere else) - Sort comparator now takes sessionAttentionStates so lastUserMessageAt / lastStatusChangeAt is used when newer than session.time.updated; all sort call-sites and their useMemo/useCallback deps updated accordingly - Remove foldersMap from cleanup effect deps to prevent cascade re-renders when folders change; read current value via getState() instead * fix(session-folders): new session is placed into the correct folder sendMessage() was calling useSessionManagementStore.createSession() directly, bypassing the targetFolderId logic in useSessionStore.createSession. Fix: read targetFolderId from draft at the top of the draft branch in sendMessage, then call addSessionToFolder immediately after the session is created and before the draft is closed. Also propagate targetFolderId through openNewSessionDraft options and NewSessionDraftState type. * feat(session-folders): add sub-folder support (one level deep) - SessionFolder gains optional parentId field for hierarchy - createFolder accepts parentId to create sub-folders - deleteFolder cascades to remove all child sub-folders - SessionFolderItem renders sub-folders before sessions in body; new sub-folder button (RiFolderAddLine) visible at depth 0 only - renderOneFolderItem in SessionSidebar builds the tree recursively; sub-folders are indented via depth prop (ml-3 on root's children) - Persist/hydrate parentId correctly from localStorage * feat(session): add delete confirm dialogs and improve subtitle UX - Add confirmation dialogs before deleting sessions or folders - Show relative time (e.g., '2h ago', '35min ago') for recent sessions - Replace +/- diff numbers with file change count (e.g., '3 files changed') - New folders use default name without forcing rename - Cleaner, less cluttered session list UI * fix(session-folders): skip folder cleanup while sessions are loading Prevents race condition on reload where cleanupSessions() runs before the server returns the full session list, causing folder-session assignments to be incorrectly wiped from localStorage. * feat(chat): per-session draft persistence and expandable input focus mode - Feature 1 (#478): preserve chat draft per session when switching projects - Replace global localStorage key with per-session key (draft_${sessionId}) - Save draft for old session on switch, restore draft for new session - Clear draft on submit - Feature 2 (#479): expandable chat input focus mode (⌘⇧E / Ctrl+Shift+E) - Add isExpandedInput state to useUIStore - Register expand_input shortcut (mod+shift+e, customizable) - Wire shortcut in useKeyboardShortcuts - Overlay portal with full-height textarea, Esc to close, auto-close on submit - Expand button with tooltip showing keyboard shortcut hint * fix(chat): switch to in-place desktop focus mode, caret-anchored autocomplete, and no-focus-jump toggle --------- Co-authored-by: Bohdan Triapitsyn --- .../ui/src/components/chat/ChatContainer.tsx | 53 ++- packages/ui/src/components/chat/ChatInput.tsx | 324 +++++++++++++++--- .../components/chat/CommandAutocomplete.tsx | 5 +- .../chat/FileMentionAutocomplete.tsx | 3 + .../src/components/chat/SkillAutocomplete.tsx | 3 + packages/ui/src/hooks/useKeyboardShortcuts.ts | 13 + packages/ui/src/lib/shortcuts.ts | 7 + packages/ui/src/stores/useUIStore.ts | 13 + 8 files changed, 372 insertions(+), 49 deletions(-) diff --git a/packages/ui/src/components/chat/ChatContainer.tsx b/packages/ui/src/components/chat/ChatContainer.tsx index 63489175..f508b65e 100644 --- a/packages/ui/src/components/chat/ChatContainer.tsx +++ b/packages/ui/src/components/chat/ChatContainer.tsx @@ -18,6 +18,7 @@ import { OverlayScrollbar } from '@/components/ui/OverlayScrollbar'; import { TimelineDialog } from './TimelineDialog'; import type { PermissionRequest } from '@/types/permission'; import type { QuestionRequest } from '@/types/question'; +import { cn } from '@/lib/utils'; const EMPTY_MESSAGES: Array<{ info: Message; parts: Part[] }> = []; const EMPTY_PERMISSIONS: PermissionRequest[] = []; @@ -101,6 +102,7 @@ export const ChatContainer: React.FC = () => { const { isTimelineDialogOpen, setTimelineDialogOpen, + isExpandedInput, } = useUIStore(); const sessionMessages = useSessionStore( @@ -163,6 +165,7 @@ export const ChatContainer: React.FC = () => { const { isMobile } = useDeviceInfo(); const draftOpen = Boolean(newSessionDraft?.open); + const isDesktopExpandedInput = isExpandedInput && !isMobile; React.useEffect(() => { if (!currentSessionId && !draftOpen) { @@ -423,13 +426,22 @@ export const ChatContainer: React.FC = () => { if (!currentSessionId && draftOpen) { return (
+ {!isDesktopExpandedInput ? (
-
+ ) : null} +
@@ -470,13 +482,22 @@ export const ChatContainer: React.FC = () => { if (sessionMessages.length === 0 && !streamingMessageId) { return (
+ {!isDesktopExpandedInput ? (
-
+ ) : null} +
@@ -485,11 +506,18 @@ export const ChatContainer: React.FC = () => { return (
-
- +
{
-
- {showScrollButton && sessionMessages.length > 0 && ( +
+ {!isDesktopExpandedInput && showScrollButton && sessionMessages.length > 0 && (
-
+
{ @@ -1908,6 +2084,7 @@ export const ChatInput: React.FC = ({ onOpenSettings, scrollToBo
= ({ onOpenSettings, scrollToBo activeTab={autocompleteTab} onTabSelect={handleAutocompleteTabSelect} onClose={() => setShowCommandAutocomplete(false)} + style={isDesktopExpanded && autocompleteOverlayPosition + ? { + left: `${autocompleteOverlayPosition.left}px`, + top: `${autocompleteOverlayPosition.top}px`, + bottom: 'auto', + width: `min(450px, calc(100% - ${autocompleteOverlayPosition.left + 8}px))`, + maxHeight: `${autocompleteOverlayPosition.maxHeight}px`, + transform: autocompleteOverlayPosition.place === 'above' ? 'translateY(-100%)' : undefined, + } + : undefined} /> )} { } @@ -1962,6 +2149,16 @@ export const ChatInput: React.FC = ({ onOpenSettings, scrollToBo searchQuery={skillQuery} onSkillSelect={handleSkillSelect} onClose={() => setShowSkillAutocomplete(false)} + style={isDesktopExpanded && autocompleteOverlayPosition + ? { + left: `${autocompleteOverlayPosition.left}px`, + top: `${autocompleteOverlayPosition.top}px`, + bottom: 'auto', + width: `min(360px, calc(100% - ${autocompleteOverlayPosition.left + 8}px))`, + maxHeight: `${autocompleteOverlayPosition.maxHeight}px`, + transform: autocompleteOverlayPosition.place === 'above' ? 'translateY(-100%)' : undefined, + } + : undefined} /> )} @@ -1976,6 +2173,16 @@ export const ChatInput: React.FC = ({ onOpenSettings, scrollToBo activeTab={autocompleteTab} onTabSelect={handleAutocompleteTabSelect} onClose={() => setShowFileMention(false)} + style={isDesktopExpanded && autocompleteOverlayPosition + ? { + left: `${autocompleteOverlayPosition.left}px`, + top: `${autocompleteOverlayPosition.top}px`, + bottom: 'auto', + width: `min(520px, calc(100% - ${autocompleteOverlayPosition.left + 8}px))`, + maxHeight: `${autocompleteOverlayPosition.maxHeight}px`, + transform: autocompleteOverlayPosition.place === 'above' ? 'translateY(-100%)' : undefined, + } + : undefined} /> )}