-
Notifications
You must be signed in to change notification settings - Fork 95
[201_63] 文本选中悬浮框拆分-功能初步实现 #2943
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e245196
文本选中悬浮框拆分-功能初步实现
Yuki-Nagori 1910496
Cleanup: Remove unused code in PR #2943
d44adc1
Optimize: Performance improvements for text toolbar
ae8804a
docs: Update 201_63.md with performance optimization details
c1ccccf
docs: Translate comments to Chinese in optimized code
05f69c6
wip
Yuki-Nagori 68a8015
加回错误的删除( tree get_shortcut_suffix (string cmd_s);)
Yuki-Nagori bad4443
fix: Improve type safety and add text toolbar tests
6d190c3
format
Yuki-Nagori e56a44b
wip
Yuki-Nagori a77ad83
Update testing instructions in 201_63.md
Yuki-Nagori 7a2fbdd
docs: Expand testing instructions in 201_63.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
|
|
||
| # 201_63 文本选中悬浮框 | ||
|
|
||
| ## 如何测试 | ||
|
|
||
| ### 手动测试 | ||
| 1. **基本功能测试** | ||
| - 选中一段文本,测试是否会弹出文本工具栏 | ||
| - 点击工具栏外部,测试是否会隐藏 | ||
| - 滚动页面,测试工具栏是否跟随移动 | ||
|
|
||
| 2. **显示条件测试** | ||
|
|
||
| **会显示的情况**(需同时满足): | ||
| - ✅ 不在数学模式(`in-math?`) | ||
| - ✅ 不在编程模式(`in-prog?`) | ||
| - ✅ 不在代码模式(`in-code?`) | ||
| - ✅ 不在原文模式(`in-verbatim?`) | ||
| - ✅ 有活动的文本选区 | ||
| - ✅ 选区内容非空 | ||
|
|
||
| **不会显示的情况**(满足任一): | ||
| - ❌ 在数学公式中选中 | ||
| - ❌ 在代码块中选中 | ||
| - ❌ 在程序块中选中 | ||
| - ❌ 在原文环境中选中 | ||
| - ❌ 没有选区(仅光标) | ||
| - ❌ 选区为空字符串 | ||
| - ❌ 正在拖拽鼠标(`left_dragging`) | ||
| - ❌ 选区不在视图范围内 | ||
|
|
||
| 3. **缓存机制测试** | ||
| - 快速移动鼠标,观察工具栏是否稳定(100ms缓存) | ||
| - 选区变化后,观察是否及时更新 | ||
|
|
||
| ### 自动测试 | ||
| ```bash | ||
| # 编译测试 | ||
| xmake b text_toolbar_test | ||
|
|
||
| # 运行测试 | ||
| xmake r text_toolbar_test | ||
| ``` | ||
|
|
||
| **测试覆盖**: | ||
| - 缓存机制验证 | ||
| - 缓存失效功能 | ||
| - 空选区处理 | ||
| - 有效选区矩形计算 | ||
| - 坐标转换一致性 | ||
|
|
||
|
|
||
| ## 2026/3/6 性能优化与代码清理 | ||
| ### What | ||
| - 基于 Chen Jie 已经实现的代码,进行拆分优化 | ||
| - 添加 should_show_text_toolbar() 缓存机制,减少 Scheme 调用 | ||
| - 消除 selection_active_any() 重复检查 | ||
| - 简化 update_text_toolbar() 中的冗余计算 | ||
|
|
||
| ### Why | ||
| - 每次鼠标移动调用 4 次 Scheme call(),性能开销大 | ||
| - selection_active_any() 被重复调用 | ||
| - min/max 计算冗余 | ||
| - 存在未使用的代码残留 | ||
|
|
||
| ### How | ||
| 1. **添加缓存字段**(edit_interface.hpp): | ||
| ```cpp | ||
| time_t text_toolbar_last_check = 0; | ||
| bool text_toolbar_last_result = false; | ||
| ``` | ||
|
|
||
| 2. **优化 should_show_text_toolbar()**: | ||
| - 使用 100ms 缓存,避免频繁 Scheme 调用 | ||
| - 缓存上次检查结果和时间戳 | ||
|
|
||
| 3. **简化 get_text_selection_rect()**: | ||
| - 单点检查 selection_active_any() | ||
| - 移除重复逻辑分支 | ||
|
|
||
| 4. **重构 update_text_toolbar()**: | ||
| - 早期返回无效矩形 | ||
| - 移除冗余 min/max 计算 | ||
| - 简化控制流程 | ||
|
|
||
| 5. **修复类型转换安全性**(edit_mouse.cpp): | ||
| - static_cast 改为 dynamic_cast | ||
| - 添加空指针检查 | ||
| ```cpp | ||
| // 修改前 | ||
| qt_simple_widget_rep* qsw = static_cast<qt_simple_widget_rep*>(this); | ||
|
|
||
| // 修改后 | ||
| if (qt_simple_widget_rep* qsw = dynamic_cast<qt_simple_widget_rep*>(this)) { | ||
| qsw->show_text_toolbar(...); | ||
| } | ||
| ``` | ||
|
|
||
| 6. **添加缓存失效方法**(edit_interface.hpp/cpp): | ||
| ```cpp | ||
| void invalidate_text_toolbar_cache(); | ||
| // 实现:text_toolbar_last_check = 0; | ||
| ``` | ||
|
|
||
| 7. **添加单元测试**(tests/Edit/Interface/text_toolbar_test.cpp): | ||
| - 测试缓存机制和失效 | ||
| - 测试矩形有效性验证 |
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
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
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
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
Oops, something went wrong.
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.
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.
apply_changes()callsupdate_text_toolbar()onTHE_SELECTION, butshould_show_text_toolbar()caches its result for 100ms. Without invalidating the cache here, a selection change can be ignored until the cache expires, causing the toolbar to show/hide late. Callinvalidate_text_toolbar_cache()(or otherwise force a recheck) beforeupdate_text_toolbar()when the selection changes.