Skip to content

[Bug] 插件视图画布里多段文字整行放得下时,最后一段仍被浮点舍入误差截成省略号 #2309

Closed

Description

@xiaoyumuxi

Platform / 平台

macOS

Area / 模块

Extensions / 扩展

Lithe version / Lithe 版本

源码构建 main 6088516(desktop-v0.8.7 起的发布版都包含引入问题的提交 270e712)

Priority / 优先级

P2 / 后续考虑:目前不着急,可安排到后续版本

OS and architecture / 操作系统与架构

macOS 27.3 (26C5047e), Apple Silicon (arm64)

Environment / 环境信息

  • 运行方式:本机源码构建的 Viva 桌面端,通过 scripts/desktop/desktop-go.sh 构建和运行无头测试,不是安装包。
  • 涉及组件:插件视图画布 desktop/internal/pluginview/canvas.go 的 painter.text,它按 runs 逐段绘制一行文字。
  • 插件:在一个语言插件的设置区域预览卡片里看到,卡片标题是两段 run(错误代码 + “ · N 个错误”),没有设 maxWidth 或 maxWidth 远大于这行字。
  • 平台范围:代码是 macOS 和 Windows 共用的 Viva 桌面端;只在 macOS 上看到,Windows 没验证。

Steps to reproduce / 复现步骤

  1. 插件视图画布里放一个 text 形状,runs 是两段,例如 bad-argument-type 和 · 2 errors,不设 maxWidth(或设成比这行宽得多的值)。
  2. 让两段的测量宽度在 float32 下相加后再减去第一段,得到的值比第二段的宽度小一个舍入误差(例如 101.3 + 62.7)。
  3. 打开显示这个画布的界面。

Expected behavior / 预期行为

整行放得下,两段都完整画出,不出现省略号。只有整行比 maxWidth 宽时才截断。

Actual behavior / 实际行为

第二段被截成 · 2 e… 这样的省略号,虽然整行完全放得下。

原因:painter.text 先把每段宽度加成 total,再从 total 里逐段减掉已画的宽度,把剩下的 left 当作下一段的可用宽度;只要 width > left 就调用 fit 截断。float32 下 total - w1 可能比 w2 小一点点,于是一行完全放得下的文字最后一段也被截断。这段逻辑在 270e712(#2183)中引入。

Logs or diagnostic output / 日志或诊断输出

$ bash scripts/desktop/desktop-go.sh test ./internal/pluginview -run TestCanvasTextDrawsRunsThatFitWhole -count=1
--- FAIL: TestCanvasTextDrawsRunsThatFitWhole
    canvas_test.go: maxWidth 0 drew ["bad-argument-type" " · 2 e…"]

Screenshots or recordings / 截图或录屏

未提供:本机截图里含有临时目录路径,改用上面的文字说明和单元测试复现。

Checklist / 提交前检查

  • I searched existing issues for duplicates. / 我已搜索现有 Issue,确认没有重复报告。
  • I removed secrets and personal data from the report. / 我已从报告中移除敏感信息和个人数据。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    review: high

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions