File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 241241(tm-define (kbd-horizontal t forwards?)
242242 (:require (graphical-text-context? t))
243243 (with-define (move) ((if forwards? go-right go-left))
244- (go-to-next-inside move (lambda (t2 ) (equal? t ( tree-ref t2 :up ))))))
244+ (go-to-next-inside move (lambda (t2 ) (tree-search-upwards t2 ( lambda ( u ) ( equal? u t) ))))))
245245
246246(tm-define (kbd-vertical t downwards?)
247247 (:require (graphical-text-context? t))
248248 (with-define (move) ((if downwards? go-down go-up))
249- (go-to-next-inside move (lambda (t2 ) (equal? t ( tree-ref t2 :up ))))))
249+ (go-to-next-inside move (lambda (t2 ) (tree-search-upwards t2 ( lambda ( u ) ( equal? u t) ))))))
250250
251251(tm-define (kbd-extremal t forwards?)
252252 (:require (graphical-text-context? t))
Original file line number Diff line number Diff line change 1+ # [ 0121] 修复绘图区域数学模式中光标左移导致的死循环
2+
3+ ## 相关文档
4+ - [ dddd.md] ( dddd.md ) - 任务文档模板
5+
6+ ## 任务相关的代码文件
7+ - ` TeXmacs/progs/graphics/graphics-kbd.scm `
8+
9+ ## 如何测试
10+
11+ ### 确定性测试(单元测试)
12+ ``` bash
13+ # 暂无单元测试
14+ ```
15+
16+ ### 非确定性测试(文档验证)
17+ 1 . 启动 Mogan,新建一个空白文档
18+ 2 . 插入一个绘图区域(如通过菜单 Insert -> Image -> Draw image)
19+ 3 . 在绘图区域中插入数学对象(如通过菜单 Insert -> Mathematics -> Formula at)
20+ 4 . 进入数学编辑模式,在公式中输入一些内容
21+ 5 . 持续按左方向键(或 Home 键),观察软件是否卡住
22+ 6 . 修复后光标应正常移动,软件不会无响应
23+
24+ ## 如何提交
25+
26+ ``` bash
27+ xmake build
28+ ```
29+
30+ ## What
31+
32+ 修复在绘图区域(graphics)的数学模式(math-at)中,按左方向键移动光标时软件卡死的问题。
33+
34+ ## Why
35+
36+ 在 ` [23_21] Ban jump in text/math at of graphics area ` 提交中,` graphics-kbd.scm ` 的 ` kbd-horizontal ` 和 ` kbd-vertical ` 使用了一个 lambda 来判断光标是否还在 ` graphical-text-context ` 内部:
37+
38+ ``` scheme
39+ (lambda (t2) (equal? t (tree-ref t2 :up)))
40+ ```
41+
42+ 该 lambda 假设 ` innermost-pattern ` 检查到的节点 ` t2 ` 的父节点就是 ` t ` (如 ` math-at ` )。但当 ` math-at ` 的内部结构比较扁平(光标直接位于 ` math-at ` 的子节点上,路径只有 3 层)时,` t2 ` 本身就是 ` math-at ` ,其 ` tree-ref :up ` 是 ` graphics ` ,不等于 ` math-at ` 。此时 ` innermost-pattern ` 永远返回假,而 ` go-left ` 又一直在改变光标位置,导致 ` go-to-next-inside-sub ` 的 ` do ` 循环永远无法退出,形成死循环。
43+
44+ ## How
45+
46+ 将 lambda 改为向上遍历祖先链进行匹配:
47+
48+ ``` scheme
49+ (lambda (t2) (tree-search-upwards t2 (lambda (u) (equal? u t))))
50+ ```
51+
52+ 这样在扁平结构(` t2 ` 本身就是 ` t ` )和嵌套结构(` t2 ` 是 ` t ` 的后代)下都能正确匹配,保证光标在 ` math-at ` 或 ` text-at ` 内部移动时不会跳出,同时也不会触发死循环。
You can’t perform that action at this time.
0 commit comments