Skip to content

[0603] 修复边注直接编辑交互#3326

Merged
JackYansongLi merged 4 commits into
mainfrom
jl/margin-notes
May 12, 2026
Merged

[0603] 修复边注直接编辑交互#3326
JackYansongLi merged 4 commits into
mainfrom
jl/margin-notes

Conversation

@JackYansongLi
Copy link
Copy Markdown
Contributor

@JackYansongLi JackYansongLi commented May 12, 2026

如何测试

  1. 编译并启动 Mogan
  2. 新建一个文档
  3. 点击菜单:插入 → 注记 → 边注(或输入 \marginal-note 后回车)
  4. 预期结果:不应出现 <marginal-note|normal|c|> 的源代码形式,而是直接渲染在页面边缘的边注,光标位于边注 body 中,可直接输入文字
  5. 选中文档中一段文字后,再插入边注,确认选中内容自动进入边注 body
  6. 点击边注使其获得焦点,确认浮动工具栏中的位置(左/右/自动)和对齐(上/中/下)设置仍可正常使用
  7. 鼠标点击测试:用鼠标直接点击页面边缘的边注 body,确认光标可以进入并编辑(此前只能用方向键移入)

修改内容

问题描述

此前插入边注时,由于 marginal-note 的 DRD 属性为 accessible|none,且 make-marginal-note 显式包裹了 inactive,导致:

  • 插入后显示源代码形式 <marginal-note|normal|c|正文>
  • 用户需要按 Enter 激活后才能看到渲染效果
  • 再次编辑时需要按 Backspace 重新进入 inactive 编辑模式

此外,边注渲染后鼠标无法点击进入编辑,只能用方向键移入。

修复方案

参考 comments 插件的实现模式(unfolded-comment 的 DRD 设为 accessible|6,插入时不包裹 inactive):

  1. 修改 DRD:将 marginal-noteaccessible 属性从 none 改为 2,使第三个参数(body)可直接编辑

    • 文件:TeXmacs/packages/standard/std-markup.ts
  2. 修改插入命令:去掉 inactive 包裹,光标路径从 (0 2 0) 改为 (2 0)

    • 文件:TeXmacs/progs/generic/generic-edit.scm
  3. 修复鼠标点击进入边注lazy_paragraph.cpp 在排版 line-note 时将其包装为 resize_box(..., 0, 0, 0, 0),导致边界框为空,phrase_box 的鼠标点击测试无法命中边注区域。改为使用 move_box 的实际边界,使鼠标可以直接点击进入边注 body。

    • 文件:src/Typeset/Line/lazy_paragraph.cpp

参考 comments 插件模式,将 marginal-note 的 accessible 属性从 none 改为 2,
使 body 可直接编辑;同时去掉 make-marginal-note 中的 inactive 包裹,
插入后不再显示 <marginal-note|...> 源代码形式。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@JackYansongLi JackYansongLi marked this pull request as draft May 12, 2026 11:17
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@JackYansongLi JackYansongLi marked this pull request as ready for review May 12, 2026 12:03
Copy link
Copy Markdown
Contributor

@da-liii da-liii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@JackYansongLi JackYansongLi merged commit 6d8e031 into main May 12, 2026
@JackYansongLi JackYansongLi deleted the jl/margin-notes branch May 12, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants