-
Notifications
You must be signed in to change notification settings - Fork 53
[201_69] 表格支持鼠标缩放 #2713
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
base: main
Are you sure you want to change the base?
[201_69] 表格支持鼠标缩放 #2713
Conversation
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.
Pull request overview
为表格新增“鼠标拖拽缩放(整体 resize handles)”能力,并配套调整表格格线拖拽(line resizing)交互所需的数据与事件处理。
Changes:
- 在渲染层新增表格缩放手柄绘制与 bbox 缓存,并基于表格类型(wide/plain)决定手柄数量
- 在鼠标事件层新增表格整体缩放的 hit/start/apply/stop 流程,并将原表格格线拖拽逻辑重构为 “line resizing”
- 扩展
table-loc?消息返回信息,补充 wide/plain 标记用于交互判断
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Typeset/Boxes/Composite/composite_boxes.cpp | 为 table-loc? 的 cell 场景追加 wide/plain 信息,支持上层交互判断 |
| src/Edit/Interface/edit_repaint.cpp | 新增表格缩放手柄绘制逻辑与 table bbox 缓存/失效刷新 |
| src/Edit/Interface/edit_mouse.cpp | 重构表格格线拖拽并新增表格整体缩放拖拽逻辑与鼠标光标命中处理 |
| src/Edit/Interface/edit_interface.hpp | 增加表格缩放/格线拖拽所需状态字段与接口声明、以及 table bbox 缓存字段 |
| devel/201_69.md | 补充该需求的开发/测试说明文档 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| int table_resizing_type= 0; // 0: N/A; 1: line resizing; 2: scale resizing | ||
| bool table_line_vertical= false; |
Copilot
AI
Jan 28, 2026
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.
table_resizing_type uses magic numbers (0/1/2) to represent states. Consider replacing with named constants or an enum (e.g., enum class table_resize_mode { none, line, scale };) to make the state machine easier to read and harder to misuse.
| table_hit current_hit; | ||
| cursor current_cursor= get_cursor (); | ||
| if (current_cursor->valid) | ||
| table_line_hit (current_cursor->ox, current_cursor->oy, current_hit); | ||
| table_scale_wide_flag= current_hit.wide_flag; | ||
|
|
Copilot
AI
Jan 28, 2026
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.
draw_table_resize_handles reads current_hit.wide_flag even when current_cursor->valid is false (or table_line_hit early-returns without initializing current_hit), which is undefined behavior and can make table_scale_wide_flag random. Initialize current_hit (or at least current_hit.wide_flag) before use and/or guard the assignment on current_cursor->valid/table_line_hit results.
| if (!is_zero (last_table_brec)) { | ||
| // 检测鼠标是否在表格 handles 上 | ||
| if (table_scale_hit (x, y)) { | ||
| over_handles= true; | ||
| if (table_scale_handle_type == 1) handle_cursor= "size_ver"; |
Copilot
AI
Jan 28, 2026
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.
In the mouse-move path, the if (!is_zero (last_table_brec)) { ... } else if (!is_zero (last_image_brec)) { ... } structure prevents image handle hit-testing and image hover/popup behavior whenever a table bbox is cached (e.g., an IMAGE inside a TABLE). Consider checking table handles first, but still falling through to image handle/hover logic when the pointer is not over a table handle.
| if (table_scale_handle_type == 2 || table_scale_handle_type == 3) | ||
| scale_x= max ( | ||
| 0.1, (double) (table_scale_initial_width + x - table_scale_start_x) / | ||
| (double) table_scale_initial_width); | ||
|
|
Copilot
AI
Jan 28, 2026
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.
table_scale_apply divides by table_scale_initial_width / table_scale_initial_height when computing scale_x/scale_y. If either initial dimension is 0, this will divide by zero. Add guards (e.g., early return when initial width/height <= 0) before the division, and ensure table_scale_handle_type that needs an axis can’t trigger scaling with a zero initial size.
| (double) table_scale_initial_height); | ||
|
|
||
| array<int> extents= et->table_get_extents (); | ||
| int rows= extents[0], cols= extents[1]; |
Copilot
AI
Jan 28, 2026
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.
table_get_extents() can return an empty array when search_format() is nil; extents[0] / extents[1] would then be out-of-bounds. Add a check (e.g., if (N(extents) < 2 || extents[0] <= 0 || extents[1] <= 0) return;) before using rows/cols in scaling.
| int rows= extents[0], cols= extents[1]; | |
| if (N (extents) < 2 || extents[0] <= 0 || extents[1] <= 0) | |
| return; | |
| int rows= extents[0], cols= extents[1]; |
[201_69] 表格支持鼠标缩放
如何测试
2026/1/28
What
How
在开发文档中详细阐述