feat(tui): 输入区多行时鼠标滚轮可上下移动光标#193
Open
lordquest wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
输入框内容(多行)时,鼠标滚轮在输入区里会滚动历史对话区,而非滚动输入框自身。
原因:旧实现里
MouseWheelMsg不判断鼠标所在区域,永远把滚轮透传给 chat 视口(
chatViewport.Update)。而输入框用 bubbletea 的 textarea 实现,其滚动由光标驱动(视口强制跟随光标),所以即便滚轮到了输入区,也只滚了背后的历史、输入内容纹丝不动。
修复
MouseWheelMsg按鼠标所在区域分流:Y > vpH):滚轮改为发KeyPressMsg(上/下),驱动 textarea 光标上下移动,由视口跟随光标实现输入区内容的上下翻看。
这样粘贴长文本后也能滚到开头。
Y <= vpH):行为不变,仍把滚轮透传给 chat 视口滚动对话。验证
新增回归测试(
tui/input_wheel_test.go):TestInputWheelScrollsCursor— 输入区滚轮下→光标下移、滚轮上→移回顶端TestWheelInHistoryAreaScrollsChat— 历史区滚轮不移动输入光标(行为不变)go test ./tui/全部通过。