Skip to content

[Cleanup] Extract duplicate mention tabs array in ChatInput handleKeyDown #340

@samzong

Description

@samzong

Problem

ChatInput/index.tsx constructs the exact same tabs array twice in handleKeyDown — once for ArrowRight/Tab and once for ArrowLeft:

Location

File: packages/desktop/src/renderer/components/ChatInput/index.tsx:240-257

// Line 240-245 (Tab/ArrowRight handler)
const tabs: MentionTab[] = [
  ...(mentionAgents.length > 0 ? (['agents'] as const) : []),
  ...(contextFolders.length > 0 ? (['local'] as const) : []),
  'tasks', 'files',
];
setMentionTab((cur) => tabs[(tabs.indexOf(cur) + 1) % tabs.length]);

// Line 252-257 (ArrowLeft handler) — IDENTICAL array
const tabs: MentionTab[] = [
  ...(mentionAgents.length > 0 ? (['agents'] as const) : []),
  ...(contextFolders.length > 0 ? (['local'] as const) : []),
  'tasks', 'files',
];
setMentionTab((cur) => tabs[(tabs.indexOf(cur) - 1 + tabs.length) % tabs.length]);

Fix Approach

Extract to a useMemo constant outside handleKeyDown:

const mentionTabs = useMemo<MentionTab[]>(() => [
  ...(mentionAgents.length > 0 ? (['agents'] as const) : []),
  ...(contextFolders.length > 0 ? (['local'] as const) : []),
  'tasks', 'files',
], [mentionAgents.length, contextFolders.length]);

Then reference mentionTabs in both handlers.

Verification

  1. Run pnpm check — must pass
  2. Open mention picker, Tab/ArrowRight/ArrowLeft between tabs — should cycle correctly

Context

  • WG: UI & Design System
  • Priority: Low (good first issue)
  • Estimated effort: ~10 minutes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/uiUI & Design System WGgood first issueGood for newcomerskind/cleanupCategorizes issue or PR as related to code cleanup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions