Skip to content

Commit 0603d0f

Browse files
authored
[201_37] 仅在文档环境中的图片允许显示悬浮菜单 (#2429)
1 parent c83f079 commit 0603d0f

File tree

6 files changed

+169
-25
lines changed

6 files changed

+169
-25
lines changed

TeXmacs/tests/tmu/201_37.tmu

Lines changed: 107 additions & 2 deletions
Large diffs are not rendered by default.

devel/201_37.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
## 如何测试
44

5-
打开 201_37.tmu,进行以下测试项:
6-
+ 将鼠标放在图片中,查看指针是否变为小手图标
7-
+ 将鼠标移出图片,查看指针是否变回正常小箭头
8-
+ 将鼠标放在图片中,查看图片上方居中位置是否出现一个横向悬浮菜单
9-
+ 在将鼠标移入图片范围内时,仔细查看是否出现了菜单位移的现象,期望不出现
10-
+ 测试左对齐、居中、右对齐按钮功能是否正常
11-
+ 弹出菜单后,上下滚动页面,菜单应始终保持在图片上方
12-
+ 查看当前对齐方式所对应的按钮是否正常高亮
13-
+ 按住ctrl/command,滚动滚轮,查看菜单大小是否跟随变化,以及悬浮菜单上边缘是否介于两行之间。
14-
+ 按住ctrl/command,持续缩小,通过 **(get-window-zoom-factor)** 获取页面缩放值, 当缩放值在 **0.35320088300220753** (即大概35.3%)及以下时,菜单应消失。
15-
+ 缓慢的将鼠标移入图片范围内,进行以下测试项:
16-
+**2025/12/26 图片悬浮菜单渲染修复** 这次修复之前,会有这样的情况:先出现了一个菜单,然后菜单消失,又出现了一个尺寸与先前不同的菜单。注意!!这个过程很短暂,需要将鼠标尽可能的接近像素级移入图片,如果移动足够缓慢,甚至可以看到先出现的菜单一直停留在页面上,直到再次移动鼠标
17-
+ 修复之后,期望鼠标移入图片范围后,菜单仅出现一次,且出现的菜单尺寸是经过调整的,与当前页面缩放相适应
5+
打开 201_37.tmu,按照其中的说明进行测试。
6+
7+
## 2025/12/31 仅在document环境中允许显示图片悬浮菜单
8+
9+
### What
10+
11+
+ 图片在表格、题注等其他环境中时,显示悬浮菜单是不合理的,现在添加判断拒绝显示。
12+
+ 粘贴图片或插入图片时亦添加判断,仅图片在document环境下才添加对齐选项。
1813

1914
## 2025/12/28 修复闪烁问题,修复坐标定位问题
2015
### What

src/Edit/Interface/edit_interface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class edit_interface_rep : virtual public editor_rep {
216216
void set_cursor_style (string style_name);
217217
void update_mouse_loci ();
218218
void update_focus_loci ();
219+
bool should_show_image_popup (tree t);
219220

220221
/* the footer */
221222
tree compute_text_footer (tree st);

src/Edit/Interface/edit_mouse.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
#include "edit_interface.hpp"
1414
#include "link.hpp"
1515
#include "message.hpp"
16+
#include "moebius/tree_label.hpp"
17+
#include "moebius/vars.hpp"
18+
#include "observer.hpp"
1619
#include "observers.hpp"
20+
#include "path.hpp"
1721
#include "qapplication.h"
1822
#include "qnamespace.h"
23+
#include "scheme.hpp"
1924
#include "sys_utils.hpp"
2025
#include "tm_buffer.hpp"
2126
#include "tm_timer.hpp"
@@ -35,6 +40,30 @@ void disable_double_clicks ();
3540

3641
bool is_in_graphics_mode= false;
3742

43+
bool
44+
edit_interface_rep::should_show_image_popup (tree t) {
45+
int t_N= N (t);
46+
if (is_nil (t)) return false;
47+
if (is_func (t, WITH) && t_N >= 2) {
48+
for (int i= 0; i < t_N; ++i) {
49+
if (t[i] == "par-mode") {
50+
return true;
51+
}
52+
}
53+
}
54+
path p= path_up (obtain_ip (t));
55+
// 持续向上遍历至最顶层的编辑树,若过程中出现了非 document
56+
// 节点,说明图片被其他节点包裹,返回 false
57+
while (p != et) {
58+
t= subtree (et, p);
59+
if (!is_func (t, DOCUMENT)) {
60+
return false;
61+
}
62+
p= path_up (p);
63+
}
64+
return true;
65+
}
66+
3867
/******************************************************************************
3968
* Routines for the mouse
4069
******************************************************************************/
@@ -603,10 +632,12 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t,
603632
if (hovering_hlink) set_cursor_style ("pointing_hand");
604633
else if (hovering_image) {
605634
set_cursor_style ("pointing_hand");
606-
path with_path= path_up (current_path);
607-
tree with_tree= subtree (et, with_path);
608-
show_image_popup (with_tree, selr, magf, get_scroll_x (), get_scroll_y (),
609-
get_canvas_x (), get_canvas_y ());
635+
path path_of_image_parent= path_up (current_path);
636+
tree tree_of_image_parent= subtree (et, path_of_image_parent);
637+
if (should_show_image_popup (tree_of_image_parent)) {
638+
show_image_popup (tree_of_image_parent, selr, magf, get_scroll_x (),
639+
get_scroll_y (), get_canvas_x (), get_canvas_y ());
640+
}
610641
}
611642
else {
612643
set_cursor_style ("normal");

src/Edit/Modify/edit_text.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,14 @@ edit_text_rep::make_image (string file_name, bool link, string w, string h,
390390
t << tuple (tree (RAW_DATA, s), utf8_to_cork (as_string (tail (image))));
391391
}
392392
t << tree (w) << tree (h) << tree (x) << tree (y);
393-
tree with (WITH);
394-
with << tree ("par-mode") << tree ("center") << t;
395-
insert_tree (with);
393+
tree st= the_line ();
394+
// 获取当前段落tree,若其为空,则插入图片时自动添加居中环境
395+
if (N (st) == 0) {
396+
tree with (WITH);
397+
with << tree ("par-mode") << tree ("center") << t;
398+
insert_tree (with);
399+
return;
400+
}
401+
insert_tree (t);
402+
return;
396403
}

src/Edit/Replace/edit_select.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include "convert.hpp"
1515
#include "cork.hpp"
1616
#include "observer.hpp"
17+
#include "observers.hpp"
1718
#include "packrat.hpp"
19+
#include "path.hpp"
1820
#include "preferences.hpp"
1921
#include "tree_modify.hpp"
2022
#include "tree_observer.hpp"
@@ -705,9 +707,12 @@ edit_select_rep::selection_paste (string key) {
705707
tree doc= generic_to_tree (s, fm);
706708
if (is_func (doc, DOCUMENT, 1)) doc= doc[0]; // temporary fix
707709
if (is_func (doc, IMAGE)) {
708-
tree with (WITH);
709-
with << tree ("par-mode") << tree ("center") << doc;
710-
doc= with;
710+
tree t= the_line ();
711+
if (N (t) == 0) {
712+
tree with (WITH);
713+
with << tree ("par-mode") << tree ("center") << doc;
714+
doc= with;
715+
}
711716
}
712717
if (mode == "math" && is_compound (doc, "math", 1)) doc= doc[0];
713718
insert_tree (doc);

0 commit comments

Comments
 (0)