-
Notifications
You must be signed in to change notification settings - Fork 625
feat(searchHistory): 优化上下键使用场景 #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes enhance chat input history navigation by ensuring that any ongoing input is saved into the search history before moving to previous or next entries with ArrowUp/ArrowDown keys. A new method, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ChatInput
participant SearchHistory
User->>ChatInput: Press ArrowUp/ArrowDown
ChatInput->>ChatInput: Check cursor position
alt At first/last line and input non-empty
ChatInput->>SearchHistory: insertAtCurrent(currentInput)
end
ChatInput->>SearchHistory: get previous/next entry
SearchHistory-->>ChatInput: Return entry
ChatInput->>ChatInput: Set editor content to entry
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Nitpick comments (3)
src/renderer/src/lib/searchHistory.ts (1)
78-78: Consider clarifying method name vs. behavior.The method is named
insertAtCurrentbut always resets the index to the end after insertion. This might be confusing for future maintainers who expect the index to remain at the insertion point.Consider either:
- Renaming to
insertAtCurrentThenResetfor clarity- Adding a comment explaining why the index is reset to the end
- Making the index reset behavior configurable
+ // Reset index to end after insertion to maintain expected navigation behavior this.currentIndex = this.history.length // 重置索引到末尾src/renderer/src/components/ChatInput.vue (2)
929-944: Good UX improvement but consider reducing code duplication.The logic correctly preserves user input before navigating search history, which enhances the user experience. However, there's significant code duplication between the ArrowUp and ArrowDown handlers.
Consider extracting the common logic:
+function preserveCurrentContentAndNavigate(direction: 'previous' | 'next') { + const currentContent = editor.getText().trim() + + // 如果当前有内容,先将其插入到搜索历史的当前位置 + if (currentContent) { + searchHistory.insertAtCurrent(currentContent) + } + + const searchResult = direction === 'previous' + ? searchHistory.getPrevious() + : searchHistory.getNext() + + if (searchResult !== null) { + editor.commands.setContent(searchResult) + } +} if (e.code === 'ArrowUp') { const contentEditableDiv = e.target as HTMLDivElement if (isCursorInFirstLine(contentEditableDiv)) { - const currentContent = editor.getText().trim() - - // 如果当前有内容,先将其插入到搜索历史的当前位置 - if (currentContent) { - searchHistory.insertAtCurrent(currentContent) - } - - const previousSearch = searchHistory.getPrevious() - if (previousSearch !== null) { - editor.commands.setContent(previousSearch) - } + preserveCurrentContentAndNavigate('previous') e.preventDefault() } } else if (e.code === 'ArrowDown') { const contentEditableDiv = e.target as HTMLDivElement if (isCursorInLastLine(contentEditableDiv)) { - const currentContent = editor.getText().trim() - - // 如果当前有内容,先将其插入到搜索历史的当前位置 - if (currentContent) { - searchHistory.insertAtCurrent(currentContent) - } - - const nextSearch = searchHistory.getNext() - if (nextSearch !== null) { - editor.commands.setContent(nextSearch) - } + preserveCurrentContentAndNavigate('next') e.preventDefault() } }Also applies to: 945-961
934-934: Consider i18n compliance for comments.The Chinese comments may not align with the coding guidelines that require i18n keys for user-facing strings. While these are code comments (not user-facing), consider using English for consistency in a multilingual codebase.
- // 如果当前有内容,先将其插入到搜索历史的当前位置 + // If current content exists, insert it at the current search history positionAlso applies to: 950-950
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/renderer/src/components/ChatInput.vue(2 hunks)src/renderer/src/lib/searchHistory.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
`src/renderer/src/**/*.{js,ts,vue}`: All user-facing strings must use i18n keys; avoid hardcoded user-visible text.
src/renderer/src/**/*.{js,ts,vue}: All user-facing strings must use i18n keys; avoid hardcoded user-visible text.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/i18n.mdc)
List of files the instruction was applied to:
src/renderer/src/components/ChatInput.vuesrc/renderer/src/lib/searchHistory.ts
`src/**/*`: 所有新功能应该在 src 目录下开发
src/**/*: 所有新功能应该在 src 目录下开发
📄 Source: CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
List of files the instruction was applied to:
src/renderer/src/components/ChatInput.vuesrc/renderer/src/lib/searchHistory.ts
`src/renderer/**/*`: 渲染进程代码放在 src/renderer
src/renderer/**/*: 渲染进程代码放在 src/renderer
📄 Source: CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
List of files the instruction was applied to:
src/renderer/src/components/ChatInput.vuesrc/renderer/src/lib/searchHistory.ts
`src/renderer/src/**/*.{vue,ts,tsx,js,jsx}`: Use scoped styles to prevent CSS conflicts between components
src/renderer/src/**/*.{vue,ts,tsx,js,jsx}: Use scoped styles to prevent CSS conflicts between components
📄 Source: CodeRabbit Inference Engine (.cursor/rules/vue-best-practices.mdc)
List of files the instruction was applied to:
src/renderer/src/components/ChatInput.vuesrc/renderer/src/lib/searchHistory.ts
`src/renderer/**/*`: Apply all code style, structure, naming, TypeScript, syntax, UI, performance, and Nuxt-specific guidelines to all files recursively under src/renderer.
src/renderer/**/*: Apply all code style, structure, naming, TypeScript, syntax, UI, performance, and Nuxt-specific guidelines to all files recursively under src/renderer.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/vue-shadcn.mdc)
List of files the instruction was applied to:
src/renderer/src/components/ChatInput.vuesrc/renderer/src/lib/searchHistory.ts
🧬 Code Graph Analysis (1)
src/renderer/src/lib/searchHistory.ts (1)
src/main/presenter/sqlitePresenter/tables/messages.ts (1)
query(300-360)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-check (x64)
🔇 Additional comments (1)
src/renderer/src/lib/searchHistory.ts (1)
49-81: Method implementation looks solid with good edge case handling.The
insertAtCurrentmethod correctly handles input validation, duplicate detection, and history size constraints. The logic flow is well-structured.
Pull Request Description
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.
*For example: I'm always frustrated when [...] *
Describe the solution you'd like
A clear and concise description of what you want to happen.
UI/UX changes for Desktop Application
If this PR introduces UI/UX changes, please describe them in detail.
Platform Compatibility Notes
If this PR has specific platform compatibility considerations (Windows, macOS, Linux), please describe them here.
Additional context
Add any other context about the pull request here.
Pull Request Description (中文)
你的功能请求是否与某个问题有关?请描述一下。
请对问题进行清晰扼要的描述。
*例如:我增加了 [...] 的功能 *
请描述你希望的解决方案
请对你希望实现的效果进行清晰扼要的描述。
桌面应用程序的 UI/UX 更改
如果此 PR 引入了 UI/UX 更改,请详细描述它们。
平台兼容性注意事项
如果此 PR 具有特定的平台兼容性考虑因素(Windows、macOS、Linux),请在此处描述。
附加背景
在此处添加关于此 Pull Request 的任何其他背景信息。
Summary by CodeRabbit
New Features
Bug Fixes