From f5d150e199d82a4330bdf38de24c817a9cb715e5 Mon Sep 17 00:00:00 2001 From: MoonL79 <151734889+MoonL79@users.noreply.github.com> Date: Thu, 9 Apr 2026 15:48:20 +0800 Subject: [PATCH] =?UTF-8?q?[221=5F3]=20=E4=BF=AE=E5=A4=8D=E6=95=B0?= =?UTF-8?q?=E5=AD=A6=20tab=20cycling=20=E8=8F=9C=E5=8D=95=E4=B8=AD=20``=20=E5=92=8C=20``=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TeXmacs/progs/kernel/gui/menu-widget.scm | 31 +++++++++++++++---- devel/221_3.md | 38 ++++++++++++++++++++++++ src/Graphics/Fonts/virtual_font.cpp | 17 +++++------ src/Scheme/L5/glue_widget.lua | 9 ++++++ src/Texmacs/Window/tm_button.cpp | 29 ++++++++++++++++++ src/Texmacs/tm_window.hpp | 1 + 6 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 devel/221_3.md diff --git a/TeXmacs/progs/kernel/gui/menu-widget.scm b/TeXmacs/progs/kernel/gui/menu-widget.scm index 1b1fd25d0b..07f6b262ca 100644 --- a/TeXmacs/progs/kernel/gui/menu-widget.scm +++ b/TeXmacs/progs/kernel/gui/menu-widget.scm @@ -527,13 +527,34 @@ ;; Symbol fields ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(define (menu-symbol-needs-typeset-preview? sym) + (in? sym '("" ""))) + +(define (make-menu-symbol-typeset-widget sym col-name) + (let* ((pre (document-get-preamble (buffer-tree))) + (master (url->system (current-buffer))) + (inits* (map cdr (cdr (tm->stree (get-all-inits))))) + (env (append (apply append inits*) (list "magnification" "1.4"))) + (doc `(with ,@env "project" ,master + (surround (hide-preamble ,pre) "" + (document (math (with "color" ,col-name ,sym))))))) + (widget-texmacs-output-transparent doc '(style (tuple "generic"))))) + +(define (make-menu-symbol-widget font sym col col-name) + (if (menu-symbol-needs-typeset-preview? sym) + (make-menu-symbol-typeset-widget sym col-name) + (widget-box font sym col #t #t))) + (define (make-menu-symbol-button style font sym opt-cmd clr) - (with col (if (greyed? style) (color "dark grey") clr) + (let* ((col-name (if (greyed? style) "dark grey" + (if (string? clr) clr "black"))) + (col (if (greyed? style) (color "dark grey") + (if (string? clr) (color clr) clr)))) (if opt-cmd - (widget-menu-button (widget-box font sym col #t #t) + (widget-menu-button (make-menu-symbol-widget font sym col col-name) (make-menu-command (apply opt-cmd '())) "" "" style) - (widget-menu-button (widget-box font sym col #t #t) + (widget-menu-button (make-menu-symbol-widget font sym col col-name) (make-menu-command (insert sym)) "" "" style)))) @@ -851,11 +872,11 @@ (symbol-completion (:string? :*) ,(lambda (p style bar?) (let ((symbol-color (if (== (get-preference "gui theme") "liii-night") "white" "black"))) - (list (make-menu-symbol p style '(roman mr medium normal 10 600 0) (color symbol-color)))))) + (list (make-menu-symbol p style '(roman mr medium normal 10 600 0) symbol-color))))) (symbol-completion* (:string? :*) ,(lambda (p style bar?) (let ((symbol-color (if (== (get-preference "gui theme") "liii-night") "#ff6666" "red"))) - (list (make-menu-symbol p style '(roman mr medium normal 10 600 -2) (color symbol-color)))))) + (list (make-menu-symbol p style '(roman mr medium normal 10 600 -2) symbol-color))))) (texmacs-output (:%2) ,(lambda (p style bar?) (list (make-texmacs-output p style)))) (texmacs-input (:%3) diff --git a/devel/221_3.md b/devel/221_3.md new file mode 100644 index 0000000000..6280b379d6 --- /dev/null +++ b/devel/221_3.md @@ -0,0 +1,38 @@ +[221_3] 修复数学 tab cycling 菜单中 `` 和 `` 显示异常 + +## 如何测试 + +测试项一:`'T'` 的 tab cycling 菜单和实际插入结果正确 +1. 进入数学输入环境 +2. 输入 `T`,连续按 `Tab` 切换候选 +3. 浏览整组候选,重点检查 `` 和 `` +4. 这两个候选应显示为完整符号,不应出现红色报错文本,也不应只显示半个符号 +5. 当前高亮候选应保持和其他候选一致的选中态颜色 +6. 在这两个候选高亮时确认输入,文档中插入的应是对应符号,且正文渲染正常 +7. ``、``、``、``、`` 的显示和输入行为应保持原样 + +## 2026/04/09 修复数学 tab cycling 菜单中组合乘号符号显示异常 + +### What +修复数学模式下,输入 `T` 后通过 tab cycling 弹出的候选菜单中,`` 和 `` 无法正常显示的问题。 + +此次修复只调整 popup 预览链: +- 这两个符号在菜单中改为使用透明的 typeset 预览 widget +- 其余候选仍保持原来的 `widget-box` 预览方式 + +### Why +`` 和 `` 不是传统数学字体中的现成 glyph,而是定义在 `TeXmacs/fonts/virtual/emu-operators.vfn` 里的虚拟组合符号。 + +此前 tab cycling 菜单走的是 `symbol-completion -> widget-box -> text_box -> font` 这条轻量预览链。 +这条链对普通符号和已有编码映射的符号可以直接取 glyph,但对 `lefttimesthree/righttimesthree` 这种需要继续展开内部虚拟名字 `times2/times4/times6/times8` 的符号支持不完整,因此会在 popup 中退化成错误文本或异常显示。 + +### How +TeXmacs/progs/kernel/gui/menu-widget.scm 为 `` 和 `` 增加单独判断,仅对这两个符号使用 `make-menu-symbol-typeset-widget` + +src/Texmacs/tm_window.hpp 声明新的透明输出 widget 接口 `texmacs_output_widget_transparent` + +src/Texmacs/Window/tm_button.cpp 新增 `texmacs_output_widget_transparent`,沿用正文 typeset 生成 box,但以透明 widget 的方式嵌入菜单,避免出现额外深色底框 + +src/Scheme/L5/glue_widget.lua 注册 Scheme 侧接口 `widget-texmacs-output-transparent` + +src/Graphics/Fonts/virtual_font.cpp 调整虚拟字体 atomic token 的解析优先级:当名字本身就在当前虚拟字体字典中时,优先继续递归展开,而不是先回退到 `base_fn` 查位图,避免 `times2/times4/times6/times8` 落入 error font diff --git a/src/Graphics/Fonts/virtual_font.cpp b/src/Graphics/Fonts/virtual_font.cpp index 348798d07b..41a257a2f8 100644 --- a/src/Graphics/Fonts/virtual_font.cpp +++ b/src/Graphics/Fonts/virtual_font.cpp @@ -263,10 +263,9 @@ virtual_font_rep::supported (scheme_tree t, bool svg) { if (r == "#28") r= "("; if (r == "#29") r= ")"; if (N (r) > 1) r= "<" * r * ">"; - if (!extend || base_fn->supports (r) || !virt->dict->contains (r)) - return base_fn->supports (r); - if (!virt->dict->contains (r)) return false; - return supported (virt->virt_def[virt->dict[r]], svg); + if (virt->dict->contains (r) && (!extend || !base_fn->supports (r))) + return supported (virt->virt_def[virt->dict[r]], svg); + return base_fn->supports (r); } if (is_func (t, TUPLE, 3) && (is_double (t[0])) && (is_double (t[1]))) @@ -450,14 +449,14 @@ virtual_font_rep::compile_bis (scheme_tree t, metric& ex) { if (r == "#29") r= ")"; if (N (r) > 1) r= "<" * r * ">"; glyph gl; - if (!extend || base_fn->supports (r) || !virt->dict->contains (r)) { - base_fn->get_extents (r, ex); - gl= base_fn->get_glyph (r); - } - else { + if (virt->dict->contains (r) && (!extend || !base_fn->supports (r))) { scheme_tree u= virt->virt_def[virt->dict[r]]; gl = compile (u, ex); } + else { + base_fn->get_extents (r, ex); + gl= base_fn->get_glyph (r); + } if (gl->width == 0 && gl->height == 0) ex->x1= ex->y1= ex->x2= ex->y2= ex->x3= ex->y3= ex->x4= ex->y4= 0; return gl; diff --git a/src/Scheme/L5/glue_widget.lua b/src/Scheme/L5/glue_widget.lua index 7231d76101..06580494a0 100644 --- a/src/Scheme/L5/glue_widget.lua +++ b/src/Scheme/L5/glue_widget.lua @@ -387,6 +387,15 @@ function main() "content" } }, + { + scm_name = "widget-texmacs-output-transparent", + cpp_name = "texmacs_output_widget_transparent", + ret_type = "widget", + arg_list = { + "content", + "content" + } + }, { scm_name = "widget-texmacs-input", cpp_name = "texmacs_input_widget", diff --git a/src/Texmacs/Window/tm_button.cpp b/src/Texmacs/Window/tm_button.cpp index 0c65f2f014..e2221b5c75 100644 --- a/src/Texmacs/Window/tm_button.cpp +++ b/src/Texmacs/Window/tm_button.cpp @@ -308,6 +308,35 @@ texmacs_output_widget (tree doc, tree style) { return widget (tm_new (b, col, false, zoom, 0, 0)); } +widget +texmacs_output_widget_transparent (tree doc, tree style) { + doc= enrich_embedded_document (doc, style); + drd_info drd ("none", std_drd); + hashmap h1 (UNINIT), h2 (UNINIT); + hashmap h3 (UNINIT), h4 (UNINIT); + hashmap h5 (UNINIT), h6 (UNINIT); + tree prj= extract (doc, "project"); + if (is_atomic (prj) && exists (url_system (prj->label))) { + tm_buffer buf= concrete_buffer_insist (url_system (prj->label)); + if (!is_nil (buf)) { + h1= copy (buf->data->ref); + h3= copy (buf->data->aux); + h5= copy (buf->data->att); + } + } + edit_env env (drd, "none", h1, h2, h3, h4, h5, h6); + initialize_environment (env, doc, drd); + tree t = extract (doc, "body"); + lazy lz= make_lazy (env, t, path ()); + format vf= + make_query_vstream_width (array (), array ()); + format rf = lz->query (LAZY_BOX, vf); + SI w = ((format_vstream) rf)->width; + box b = (box) lz->produce (LAZY_BOX, make_format_width (w)); + double zoom= (retina_zoom == 2 ? 1.0 : 1.2); + return widget (tm_new (b, white, true, zoom, 0, 0)); +} + array get_texmacs_widget_size (widget wid) { array ret; diff --git a/src/Texmacs/tm_window.hpp b/src/Texmacs/tm_window.hpp index 5ca7b970b9..3a31fa971b 100644 --- a/src/Texmacs/tm_window.hpp +++ b/src/Texmacs/tm_window.hpp @@ -103,6 +103,7 @@ typedef tm_view_rep* tm_view; typedef tm_window_rep* tm_window; widget texmacs_output_widget (tree doc, tree style); +widget texmacs_output_widget_transparent (tree doc, tree style); widget texmacs_input_widget (tree doc, tree style, url wname); bool is_embedded_buffer (url name); array get_texmacs_widget_size (widget wid);