Skip to content

Conversation

@yumushang
Copy link

@yumushang yumushang commented Aug 15, 2025

EditorSender 组件
1、增加clear事件,方便监听clear后,清空上传的文件。
2、增加暴露实例的submit方法,方便直接通过函数调用提交方法。

Summary by CodeRabbit

  • New Features

    • EditorSender now emits a "clear" event when content is cleared, passing the inserted text as payload; the cursor moves to the end for smoother typing.
    • EditorSender ref exposes a submit() method to programmatically submit input.
  • Documentation

    • Chinese docs updated to document the new "clear" event and the submit() method with usage and parameter details.

@coderabbitai
Copy link

coderabbitai bot commented Aug 15, 2025

Walkthrough

Adds an EditorSender clear(txt: string) event and exposes a public submit(): void method. Component emits clear after clearing and repositioning the cursor; docs and TypeScript emit declarations updated accordingly.

Changes

Cohort / File(s) Summary
Docs: EditorSender (ZH)
apps/docs/zh/components/editorSender/index.md
Documented new event clear(txt: string) and new Ref method submit(): void.
Component: EditorSender implementation
packages/core/src/components/EditorSender/index.vue
Emits clear with txt payload in onClear; exposes submit() via defineExpose as alias of onSubmit.
Types: EditorSender emits
packages/core/src/components/EditorSender/types.d.ts
Added emit overload for clear event to EditorSenderEmits ((e: 'clear', txt: string): void).

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant EditorSender
  participant Consumer

  User->>EditorSender: Trigger clear action
  EditorSender->>EditorSender: Clear content & move cursor to end
  EditorSender-->>Consumer: emit("clear", txt)
Loading
sequenceDiagram
  participant Consumer
  participant EditorSender

  Consumer->>EditorSender: call submit()
  EditorSender->>EditorSender: onSubmit()
  EditorSender-->>Consumer: proceed with submission flow
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

I hopped through text and brushed it clear,
A tiny thump — the cursor near.
“Submit,” I whispered, paw on key,
Events now sing, both swift and neat,
A rabbit's patch of code complete. 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
packages/core/src/components/EditorSender/index.vue (1)

177-182: ESLint: add space after comma in emits('clear', txt)

Static analysis flagged a comma-spacing error at Line 181. Fix to satisfy lint and keep style consistent.

-  emits('clear',txt);
+  emits('clear', txt);
🧹 Nitpick comments (1)
apps/docs/zh/components/editorSender/index.md (1)

135-135: Align docs with implementation: make txt optional for 'clear'

Implementation emits txt optionally and types.ts uses txt?: string. Update docs to reflect optional parameter.

-| `clear`            | 清空内容时触发      | `txt: string` - 参数txt为清空后插入的文本            |
+| `clear`            | 清空内容时触发      | `txt?: string` - 可选参数txt为清空后插入的文本       |
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 655ec3d and 034446f.

📒 Files selected for processing (3)
  • apps/docs/zh/components/editorSender/index.md (2 hunks)
  • packages/core/src/components/EditorSender/index.vue (2 hunks)
  • packages/core/src/components/EditorSender/types.d.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/core/src/components/EditorSender/types.d.ts (6)
packages/core/src/components/Sender/types.d.ts (2)
  • SenderEmits (53-66)
  • TriggerEvent (46-51)
packages/core/src/components/MentionSender/types.d.ts (1)
  • MentionSenderEmits (52-65)
packages/core/src/components/BubbleList/types.d.ts (1)
  • BubbleListEmits (27-29)
packages/core/src/components/Conversations/types.d.ts (1)
  • ConversationsEmits (101-109)
packages/core/src/components/Typewriter/types.d.ts (1)
  • TypewriterEmits (26-30)
packages/core/src/components/ThoughtChain/types.d.ts (1)
  • ThoughtChainEmits (126-128)
apps/docs/zh/components/editorSender/index.md (1)
packages/core/src/components/Sender/types.d.ts (2)
  • SenderEmits (53-66)
  • SenderProps (1-44)
packages/core/src/components/EditorSender/index.vue (1)
packages/core/src/components/Sender/types.d.ts (1)
  • SenderEmits (53-66)
🪛 ESLint
packages/core/src/components/EditorSender/index.vue

[error] 181-181: A space is required after ','.

(style/comma-spacing)


[error] 460-460: Missing space before value for key 'submit'.

(style/key-spacing)

🔇 Additional comments (1)
apps/docs/zh/components/editorSender/index.md (1)

146-146: LGTM: submit() instance method is documented correctly

Matches the exposed method in index.vue and PR objective.

@yumushang yumushang force-pushed the feat-banwan branch 2 times, most recently from e72fe8c to c7448cc Compare August 15, 2025 06:40
EditorSender
1、增加clear事件
2、增加暴露实例的submit方法
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/core/src/components/EditorSender/index.vue (1)

360-375: Falsy rank check can skip rank 0; check nullish instead

if (!rank) wrongly treats 0 as not-found, breaking updates for the first node.

Apply this diff:

 function updateSelectTag(elm: HTMLElement, tag: TagInfo) {
   const rank = opNode.value?.getRankByElm(elm.parentElement!);
-  if (!rank) {
+  if (rank == null) {
     return;
   }
   const chatNode = opNode.value?.getNodeByRank(rank);
   if (!chatNode) {
     return;
   }
🧹 Nitpick comments (1)
packages/core/src/components/EditorSender/index.vue (1)

177-182: Fix ESLint comma-spacing in clear emit

Missing space after comma triggers ESLint: A space is required after ','.

Apply this diff:

 function onClear(txt?: string) {
   chat.value!.clear(txt);
   // 将光标移动到末尾
   focusToEnd();
-  emits('clear',txt);
+  emits('clear', txt);
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 034446f and 7286a38.

📒 Files selected for processing (3)
  • apps/docs/zh/components/editorSender/index.md (2 hunks)
  • packages/core/src/components/EditorSender/index.vue (2 hunks)
  • packages/core/src/components/EditorSender/types.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/components/EditorSender/types.d.ts
  • apps/docs/zh/components/editorSender/index.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/components/EditorSender/index.vue (1)
packages/core/src/components/Sender/types.d.ts (1)
  • SenderEmits (53-66)
🪛 ESLint
packages/core/src/components/EditorSender/index.vue

[error] 181-181: A space is required after ','.

(style/comma-spacing)

🔇 Additional comments (2)
packages/core/src/components/EditorSender/index.vue (2)

458-467: Expose submit via defineExpose — LGTM

submit is now publicly exposed and spacing is correct. This aligns with the PR goals and the earlier lint warning has been addressed.


50-51: EditorSender emits typing includes 'clear' — verified

Verified: EditorSenderEmits declares the clear event and the implementation emits it; no consumer-facing typing changes missing.

Files checked:

  • packages/core/src/components/EditorSender/types.d.ts — contains "(e: 'clear', txt: string): void"
  • packages/core/src/components/EditorSender/index.vue — defines onClear(txt?: string) and calls emits('clear', txt)
  • packages/core/src/components/EditorSender/components/ClearButton/index.vue — emits 'clear' from the button

No changes required.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/core/src/components/EditorSender/index.vue (2)

20-21: Import missing Vue APIs used below.

getCurrentInstance and computed are used but not imported, causing TS/compile errors.

Apply:

-import { onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
+import { onBeforeUnmount, onMounted, reactive, ref, watch, computed, getCurrentInstance } from 'vue';

Also applies to: 52-56


48-51: Make txt optional in the ‘clear’ emit signature
In packages/core/src/components/EditorSender/types.d.ts (line 77), change

(e: 'clear', txt: string): void;

to

(e: 'clear', txt?: string): void;
♻️ Duplicate comments (1)
packages/core/src/components/EditorSender/index.vue (1)

473-476: Expose submit API: spacing fix looks good and resolves prior lint.

submit: onSubmit now matches key-spacing convention noted in an earlier review.

🧹 Nitpick comments (3)
packages/core/src/components/EditorSender/index.vue (3)

188-188: Fix ESLint comma-spacing in clear emit.

Missing space after comma triggers style/comma-spacing.

Apply:

-  emits('clear',txt);
+  emits('clear', txt);

172-178: Make submit emptiness check source-of-truth.

Use the editor’s actual state at submit time to avoid stale chatState.isEmpty.

 function onSubmit() {
-  // 内容纯空 拦截发送
-  if (chatState.isEmpty) {
+  // 内容纯空 拦截发送
+  if (chat.value?.isEmpty(true)) {
     return;
   }
   emits('submit', getCurrentValue());
 }

184-189: Ensure UI state syncs immediately after clear.

If clear() doesn’t emit your operate hook, chatState may stay stale. Update it or emit change explicitly.

 function onClear(txt?: string) {
   chat.value!.clear(txt);
   // 将光标移动到末尾
   focusToEnd();
+  // 保证状态同步(若底层未触发 operate)
+  chatState.isEmpty = chat.value!.isEmpty(true);
+  chatState.textLength = chat.value!.textLength;
   emits('clear', txt);
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7286a38 and 727e2a5.

📒 Files selected for processing (3)
  • apps/docs/zh/components/editorSender/index.md (2 hunks)
  • packages/core/src/components/EditorSender/index.vue (2 hunks)
  • packages/core/src/components/EditorSender/types.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/components/EditorSender/types.d.ts
  • apps/docs/zh/components/editorSender/index.md
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/components/EditorSender/index.vue (1)
packages/core/src/components/Sender/types.d.ts (2)
  • SenderEmits (53-66)
  • TriggerEvent (46-51)
🪛 ESLint
packages/core/src/components/EditorSender/index.vue

[error] 188-188: A space is required after ','.

(style/comma-spacing)

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