Repository navigation
fix(desktop): 插件画布多段文字整行放得下时不再截断最后一段 (#2309) - #2310
Merged
Merged
Conversation
painter.text 从各段宽度之和里逐段减去已画宽度,把剩余当作下一段的可用宽度。 float32 下剩余值可能比最后一段的宽度小一个舍入误差,整行放得下也会被截成省略号。 现在只有整行超过 maxWidth 才截断,并补回归测试。
xiaoyumuxi
marked this pull request as ready for review
November 22, 2026 15:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
插件视图画布里,一行文字由几段
runs组成时(例如错误代码加“ · 2 个错误”),整行明明放得下,最后一段还是会被截成· 2 e…。原因是逐段扣减可用宽度时,float32 的舍入误差让剩下的宽度比最后一段小了一点点。改动 / Changes
desktop/internal/pluginview/canvas.go的painter.text:先判断整行是否超过maxWidth,只有超过时才按剩余宽度截断某一段并加省略号。整行放得下(或没设maxWidth)时,每段按自己的宽度完整绘制,不再和舍入后的剩余宽度比较。desktop/internal/pluginview/canvas_test.go:新增TestCanvasTextDrawsRunsThatFitWhole。它用固定宽度的测量函数构造出舍入误差(101.3 + 62.7),检查两件事:maxWidth为 0 或 400 时两段都完整绘制;maxWidth为 130 时第二段仍会截断并以…结尾。不在本 PR 范围内 / Out of scope
无
类型专属:fix
复现与根因
text形状带两段runs,宽度在 float32 下满足(w1 + w2) - w1 < w2。不设maxWidth,或设成比整行宽得多的值。room = min(total, maxWidth)加上if width > left逐段截断。用git log -S 'if width > left'和git log -S 'room = min(total'定位,都只命中这个提交。desktop-v0.8.7 起的版本都包含它。检查项
desktop/internal/pluginview/canvas_test.go的TestCanvasTextDrawsRunsThatFitWhole,修复前输出maxWidth 0 drew ["bad-argument-type" " · 2 e…"]。painter.text只在canvas.go的形状绘制分支调用一次;没有另一平台的实现,也没有插件、SDK 或脚本直接调用。.agents/notes/implemented/bug-fix/记录:行为约束(只有超过maxWidth才截断)已写在代码注释和回归测试里。范围检查 / Scope checks
功能矩阵 / Feature matrix
N/A:修正已有画布文字的绘制错误,没有新增能力,也不改变跨平台行为。
插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空。shared/i18n/;插件的构建步骤、资源路径和补丁没有写进docs/ci-builds.md、Agent Note 或 Skill。maxWidth的截断行为不变。UI 验证 / UI evidence
统一日志系统 / Structured logging
N/A:没有新增或改动生命周期、终态、降级或失败路径。
界面文案 / i18n
N/A:没有新增或修改界面文字。
逻辑归属 / Logic placement
N/A:只改桌面端绘制,没有可共享的业务逻辑。
性能与内存 / Performance and memory
N/A:没有新增后台功能、缓存、子进程或依赖。绘制时多一次比较,测量次数不变。
设置 / Settings
N/A:没有新增或修改设置。
插件契约 / Plugin contract
N/A:不涉及 Core 契约、能力版本或宿主方法。
发行包与资源 / Bundle and resources
N/A:没有新增或修改运行时资源。
无用代码与重构 / Dead code and refactoring
refactor标签的 Issue:本次没有发现。验证 / Verification
bash scripts/desktop/desktop-go.sh test ./internal/pluginview -run TestCanvasTextDrawsRunsThatFitWhole -count=1(修复前)maxWidth 0 drew ["bad-argument-type" " · 2 e…"]bash scripts/desktop/desktop-go.sh test ./internal/pluginview -count=1(修复后,rebase 到 5ab0ac8)bash scripts/desktop/desktop-go.sh vet ./internal/pluginviewgofmt -l desktop/internal/pluginviewdevelop-lithe第三节)未能执行的检查和原因:
提交前确认 / Final checks
main创建(已 rebase 到 5ab0ac8),目标分支为main。.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图。