Skip to content

Commit ea644e4

Browse files
da-liiiclaude
andauthored
[1247] 修复 image-and-ocr-paste 与 is-clipboard-image? 对外部图片剪贴板取错 child (#4441)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent e537ce1 commit ea644e4

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

TeXmacs/progs/generic/generic-edit.scm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,8 @@
12471247
;; (image-and-ocr-paste)
12481248
(tm-define (image-and-ocr-paste)
12491249
(with data
1250-
(parse-texmacs-snippet (tree->string (tree-ref (clipboard-get "primary") 0)))
1250+
;; 外部剪贴板树为 (extern <snippet-string>),内容在 child 1
1251+
(parse-texmacs-snippet (tree->string (tree-ref (clipboard-get "primary") 1)))
12511252
(when (tree-is? (tree-ref data 0) 'image)
12521253
(kbd-paste)
12531254
(kbd-return)

TeXmacs/progs/generic/paste-widget.scm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@
112112

113113
(tm-define (is-clipboard-image?)
114114
(with data
115-
(parse-texmacs-snippet (tree->string (tree-ref (clipboard-get "primary") 0)))
115+
;; 外部剪贴板树为 (extern <snippet-string>),内容在 child 1
116+
(parse-texmacs-snippet (tree->string (tree-ref (clipboard-get "primary") 1)))
116117
(if (tree-is? (tree-ref data 0) 'image) #t #f)
117118
) ;with
118119
) ;tm-define

devel/1247.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# [1247] 修复 image-and-ocr-paste 与 is-clipboard-image? 对外部图片剪贴板取错 child
2+
3+
## 1 相关文档
4+
- [dddd.md](dddd.md) - 任务文档模板
5+
- [1246.md](1246.md) - 同成因的前序修复(ocr-paste)
6+
- [2049.md](2049.md) - 引入回归的任务:将剪贴板内容索引由 1 改为 0
7+
(修软件内复制、断外部图片)
8+
9+
## 2 任务相关的代码文件
10+
- `TeXmacs/progs/generic/generic-edit.scm``image-and-ocr-paste`
11+
- `TeXmacs/progs/generic/paste-widget.scm``is-clipboard-image?`
12+
13+
## 3 如何测试
14+
15+
### 3.1 确定性测试(单元测试)
16+
无(GUI 剪贴板路径)。
17+
18+
### 3.2 非确定性测试(文档验证)
19+
手动测试步骤(GUI):
20+
21+
1. 启动 Mogan(`xmake b stem && xmake r stem`),新建空白文档
22+
2. 系统截图(或从浏览器复制一张图片)到剪贴板
23+
3. 右键菜单打开「选择性粘贴」(Paste Special)对话框:
24+
- 应出现 OCR / Image and OCR / Only image 三个图片选项
25+
- 修复前 `is-clipboard-image?` 恒 #f,只会出现普通文本格式列表
26+
4. 选 Image and OCR 确认:应先插入原图,回车分隔,随后插入云识别结果
27+
5. 回归:Ctrl+Shift+V(或右键 Magic paste)应只插入识别结果
28+
(1246 修复的路径,不受本次改动影响)
29+
6. 回归:复制纯文本(软件外),右键「选择性粘贴」应出现普通格式
30+
列表,各格式粘贴正常
31+
32+
## 4 如何提交
33+
34+
```bash
35+
gf fmt TeXmacs/progs/generic/generic-edit.scm TeXmacs/progs/generic/paste-widget.scm
36+
```
37+
38+
## 5 What
39+
`image-and-ocr-paste``is-clipboard-image?` 的剪贴板 snippet 提取由
40+
child 0 改为 child 1(仅外部剪贴板路径,与 1246 的 ocr-paste 修复一致)。
41+
42+
## 6 Why
43+
外部剪贴板树为 `("extern" <snippet-string>)`:child 0 是标签 `"extern"`
44+
内容在 child 1(C++ 侧 `qt_gui.cpp` 构造 `tuple("extern", s)`
45+
`edit_select.cpp` 消费 `t[1]`)。#4081 将这两处由 1 改为 0,外部图片
46+
剪贴板恒解析失败:图片菜单探测恒 #f、Image and OCR 粘贴不生效。
47+
48+
## 7 How
49+
仅改两处索引 0 -> 1;软件内复制的内部形状("texmacs" 元组)不在本次
50+
范围内,维持现状。

0 commit comments

Comments
 (0)