Skip to content

refactor(web): extract @-mention menu into a composable#1030

Merged
wbxl2000 merged 1 commit into
mainfrom
refactor/web-extract-mention-menu
Jun 23, 2026
Merged

refactor(web): extract @-mention menu into a composable#1030
wbxl2000 merged 1 commit into
mainfrom
refactor/web-extract-mention-menu

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

Part of the apps/kimi-web god-component split tracked in web-refactor-plan.md (follows #1011 useInputHistory, #1026 useSlashMenu). This is the next Composer slice. No standalone issue.

Problem

Composer.vue is still the largest component (~2035 lines after #1026). The @ file-mention menu is a self-contained feature — its open/items/active/loading state, the @token detection, the debounced search, and insertion — that lived inline in the composer alongside the draft, the slash menu, attachments, and the keydown orchestration.

What changed

  • New apps/kimi-web/src/composables/useMentionMenu.ts:
    • Owns the open / items / active / loading state, the @token detection, the debounced search, and select(item) insertion.
    • Takes { text, textareaRef, autosize, searchFiles } as deps — same DI shape as useSlashMenu / useInputHistory.
  • Composer.vue:
    • Replaces the inline mention section with a useMentionMenu(...) call, destructured back to the original names (mentionOpen, mentionItems, mentionActive, mentionLoading, updateMentionMenu, selectMentionItem) so the rest of the component — the keydown navigation, handleSubmit, handleSteer, and the <MentionMenu> template binding — is unchanged.
    • 2035 → 1987 lines.
  • Moved the FileItem view type into types.ts (mirroring the earlier FileData move) so the .ts composable can import it without tripping the type-aware lint rule against importing types from .vue files. MentionMenu.vue re-exports it, so the existing .vue consumers (Composer, ChatDock, ConversationPane) keep working unchanged.
  • Added test/mention-menu.test.ts (6 cases: update with/without @token, missing searchFiles, search results, search error, and select insertion / no-op).

No user-visible behavior change. Logic moved verbatim; only the call sites were re-wired.

Verification

  • pnpm --filter @moonshot-ai/kimi-web typecheck — pass (vue-tsc --noEmit)
  • pnpm --filter @moonshot-ai/kimi-web test — 70 passed
  • pnpm --filter @moonshot-ai/kimi-web build — pass
  • oxlint --type-aware on the changed files — 0 warnings, 0 errors

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (test/mention-menu.test.ts.)
  • Ran gen-changesets skill, or this PR needs no changeset. (Added .changeset/web-extract-mention-menu.md, patch on @moonshot-ai/kimi-code.)
  • Ran gen-docs skill, or this PR needs no doc update. (No user-facing change.)

Move the @-mention menu's open/items/active/loading state, the @token
detection, debounced search, and insertion logic out of Composer into
useMentionMenu. The composer keeps the keydown orchestration (it also
juggles the slash menu and history recall) and consumes the returned refs
directly; the destructured refs are aliased back to the original names so
the rest of the component is unchanged.

Move the FileItem view type into types.ts (mirroring the FileData move) so
the .ts composable can import it without hitting the type-aware lint rule
against importing types from .vue files; MentionMenu re-exports it for the
existing .vue consumers.

Composer.vue: 2035 -> 1987 lines. Adds unit tests for useMentionMenu. No
behavior change.
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aa300c0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@aa300c0
npx https://pkg.pr.new/@moonshot-ai/kimi-code@aa300c0

commit: aa300c0

@wbxl2000 wbxl2000 merged commit 661c1fb into main Jun 23, 2026
9 checks passed
@wbxl2000 wbxl2000 deleted the refactor/web-extract-mention-menu branch June 23, 2026 10:38
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant