feat: add autoReplace support for sender and update voice button document#315
feat: add autoReplace support for sender and update voice button document#315SonyLeo wants to merge 3 commits intoopentiny:developfrom
Conversation
WalkthroughThe pull request updates the voice input recognition system, changing the mode paradigm from Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Button as VoiceButton
participant Speech as Speech Engine
participant Editor as Editor/Document
rect rgba(255, 200, 100, 0.5)
Note over User,Editor: Old Flow: Final-Only Insertion
User->>Button: Click to record
Button->>Speech: Start recognition
Speech-->>Button: onInterim (transcript update)
Button->>Button: Emit interim event only
Speech-->>Button: onFinal (final transcript)
Button->>Editor: Insert transcript (if autoInsert)
Button->>Editor: Focus editor
end
rect rgba(100, 200, 255, 0.5)
Note over User,Editor: New Flow: Real-Time autoReplace Mode
User->>Button: Click to record
Button->>Speech: Start recognition (autoReplace: true)
Speech-->>Button: onInterim (transcript update)
Button->>Button: insertTranscript() with speechRange
Button->>Editor: Replace text from position 0 to N
Button->>Button: Update speechRange end position
Speech-->>Button: onInterim (refined transcript)
Button->>Editor: Replace text from position 0 to M
Button->>Button: Update speechRange end position
Speech-->>Button: onFinal (final transcript)
Button->>Button: Reset speechRange, skip insertion
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
📦 Package Previewpnpm add https://pkg.pr.new/@opentiny/tiny-robot@855ae9e pnpm add https://pkg.pr.new/@opentiny/tiny-robot-kit@855ae9e pnpm add https://pkg.pr.new/@opentiny/tiny-robot-svgs@855ae9e commit: 855ae9e |
… to append/replace
4c60cae to
855ae9e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/components/src/sender-actions/voice-button/index.vue (1)
25-57: Consider simplifyingspeechRangestate.The
speechRange.tofield is tracked (line 54) but never read—the replacement always usesdocSizeas the end position. Sincefromis always0for autoReplace mode, you could simplify to just a boolean flag indicating whether a recording session has started.However, if this tracking is intentional for future features (e.g., partial replacement from cursor position), feel free to keep it.
♻️ Optional simplification
-const speechRange = ref<{ from: number; to: number } | null>(null) +const hasStartedRecording = ref(false) const resetSpeechRange = () => { - speechRange.value = null + hasStartedRecording.value = false } const insertTranscript = (transcript: string) => { // ... early returns ... // autoReplace 模式:替换整个输入框内容 - if (speechRange.value === null) { - speechRange.value = { - from: 0, - to: 0, - } - } + hasStartedRecording.value = true const docSize = editorInstance.state.doc.content.size - const tr = editorInstance.state.tr.insertText(transcript, speechRange.value.from, docSize) + const tr = editorInstance.state.tr.insertText(transcript, 0, docSize) editorInstance.view.dispatch(tr) - speechRange.value = { - from: speechRange.value.from, - to: speechRange.value.from + transcript.length, - } editorInstance.commands.focus('end') }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/components/src/sender-actions/voice-button/index.vue` around lines 25 - 57, The speechRange.to field is never read in insertTranscript (autoReplace uses docSize), so simplify state by removing speechRange.to and either replace speechRange with a boolean like speechStarted or keep only speechRange.from; update insertTranscript to initialize and check that flag (e.g., speechStarted or speechRange.from === 0) and use speechRange.from (or 0) as the insert start, and update the single state field accordingly; ensure references to speechRange.value.to are removed and editorInstance, autoReplace, and insertTranscript behavior remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/src/components/sender.md`:
- Line 1: The file docs/src/components/sender.md contains a UTF-8 BOM (U+FEFF)
at the start; remove the BOM so the file begins with the first markdown
character and re-save the file as UTF-8 without BOM (e.g., strip the leading
U+FEFF or re-encode), ensuring consistency with speech.types.ts which was
corrected earlier.
In `@packages/components/src/sender-actions/voice-button/speech.types.ts`:
- Line 1: The file speech.types.ts contains a UTF‑8 BOM at the very start;
remove the leading BOM character so the file begins with the first TypeScript
token, re-save the file as UTF‑8 without BOM, and re-commit; if your editor adds
BOMs automatically, update its save settings (or run a one-time clean-up
command) to ensure speech.types.ts stays UTF‑8 without BOM.
---
Nitpick comments:
In `@packages/components/src/sender-actions/voice-button/index.vue`:
- Around line 25-57: The speechRange.to field is never read in insertTranscript
(autoReplace uses docSize), so simplify state by removing speechRange.to and
either replace speechRange with a boolean like speechStarted or keep only
speechRange.from; update insertTranscript to initialize and check that flag
(e.g., speechStarted or speechRange.from === 0) and use speechRange.from (or 0)
as the insert start, and update the single state field accordingly; ensure
references to speechRange.value.to are removed and editorInstance, autoReplace,
and insertTranscript behavior remain unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: cc096f6e-f1c4-4f6d-b278-1a831a223417
📒 Files selected for processing (4)
docs/demos/sender/voice-input.vuedocs/src/components/sender.mdpackages/components/src/sender-actions/voice-button/index.vuepackages/components/src/sender-actions/voice-button/speech.types.ts
| @@ -1,4 +1,4 @@ | |||
| --- | |||
| --- | |||
There was a problem hiding this comment.
UTF-8 BOM character detected at file start.
Similar to speech.types.ts, this file has a UTF-8 BOM at the start. Consider removing it for consistency.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/src/components/sender.md` at line 1, The file
docs/src/components/sender.md contains a UTF-8 BOM (U+FEFF) at the start; remove
the BOM so the file begins with the first markdown character and re-save the
file as UTF-8 without BOM (e.g., strip the leading U+FEFF or re-encode),
ensuring consistency with speech.types.ts which was corrected earlier.
| @@ -1,4 +1,4 @@ | |||
| /** | |||
| /** | |||
There was a problem hiding this comment.
UTF-8 BOM character detected at file start.
The file begins with a UTF-8 BOM (), which is unusual for TypeScript files and may cause issues with some tools or editors. Consider removing it.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/components/src/sender-actions/voice-button/speech.types.ts` at line
1, The file speech.types.ts contains a UTF‑8 BOM at the very start; remove the
leading BOM character so the file begins with the first TypeScript token,
re-save the file as UTF‑8 without BOM, and re-commit; if your editor adds BOMs
automatically, update its save settings (or run a one-time clean-up command) to
ensure speech.types.ts stays UTF‑8 without BOM.

autoReplace功能voice-input案例说明Summary by CodeRabbit
New Features
Documentation