Repository navigation
fix(base): Secure 输入框擦除、容器状态含子元素、命名控件保留名字,vet 新增 named-leaf - #88
Merged
Merged
Conversation
新增 text.Editor.Wipe 和 base.Field.Wipe,把文本与撤销历史的缓冲区清零。绑定字符串的 Secure 输入框在页面不再保留它时、以及程序替换或清空它的值时擦除,对话框关闭后密码不再留在编辑器和撤销历史里等垃圾回收。
指针移到行里的按钮上时,行不再算作离开悬停,跟随它的元素(悬停才出现的按钮)不会在指针碰到它时消失。新增 Box.StateWithin 读取同样的状态。类似 CSS 的 :hover 和 :focus-within。
两个命名的开关绑定的值在两次绘制之间互换地址时,身份跟着地址对调,键盘焦点跳到另一个开关,空格翻转的是另一个。现在名字在上一帧被别的控件占着时,命名控件保留自己的名字;移到上一帧没人占的新位置时仍跟着值,焦点不丢。不命名的控件行为不变。
给 Text、Textf、Paragraph、Wrap、Icon、Image、Spacer、Divider、Spinner 加 Key 或 Part,dev 构建会停下,release 构建丢掉名字。viva vet 现在在编译期报告,Ctx.Part 的文档写明规则。
This was referenced Dec 2, 2026
xiaoyumuxi
marked this pull request as ready for review
December 2, 2026 07:00
16 of 19 tasks
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.
背景
Lithe 的 AI 管理窗口新增供应商页(1lck/Lithe-IDEA#2511),用到密钥输入框、悬停才出现的行内按钮、放在列表里的开关。做的时候碰到四处 Viva 的问题,应用层只能绕过。这里在 Viva 里修掉,Lithe 那边的绕过代码同时删除。
改动
1. Secure 输入框不再声明或被程序改值时,擦除文本和撤销历史(6aa33128)
Secure()的输入框从界面上消失(比如对话框关闭)后,编辑器里的明文和撤销、重做历史还留在页面状态里;程序把绑定的字符串清空,撤销历史里仍然有旧的密钥。text.Editor.Wipe()、base.Field.Wipe(),应用可以在提交后主动擦除。2.
StateFrom跟随的容器,把里面的元素也算进悬停、按下和焦点(dadfa5d3)reveal.StateFrom(row)只在指针正好落在row自己身上时算悬停。指针移到行里的按钮上,行就不算悬停了,“悬停才出现”的按钮会在指针移上去的瞬间消失。StateFrom的来源是容器时,指针或焦点在它里面任何元素上都算。新增Box.StateWithin(),让元素自己的状态也按这个规则算。Hovered()等读取方法语义不变。3. 用
Key或Part命名的控件,绑定值换地址后保留自己的名字(6231e31e)Key或Part也没用,因为指针优先。Key或Part起了名字时,身份取这个名字;没有起名字的控件仍然取指针,行为不变。4.
viva vet新增named-leaf检查(8dbe2342)Text、Icon等没有身份的元素传c.Part(...)或Key不起作用,而且不会报错。viva vet现在报告这种写法,并在Ctx.Part的文档里写明。5. 文档(8bcd8255)
recipes.md、viva init生成的AGENTS.md写明:容器状态含子元素、命名控件保留名字、叶子元素不起名。测试
text/wipe_test.go:擦除后缓冲区、撤销、重做都为空,原底层数组已清零。ui/secure_wipe_test.go:Secure 输入框不再声明后擦除;程序改值后擦除;普通输入框不受影响。ui/state_within_test.go、base/style_test.go:指针在子元素上时StateFrom的跟随者保持悬停;StateWithin;没有用到的元素不受影响。ui/switch_key_test.go:命名的开关绑定值每帧换地址,身份和动画状态保留;没命名的开关行为不变。cmd/viva/vet_test.go:named-leaf命中与不命中的用例。本机(macOS)运行:
gofmt -lgo vet ./base ./ui ./text ./cmd/vivago test -tags dev ./base ./ui ./textgo test ./cmd/viva -run VetLithe 桌面端固定到“当前固定提交 727a1c1 + 这五个提交”(分支
pin/lithe-ai-window-viva-gaps,4ebb11c8)后,桌面端全量测试通过。没有做:Windows 和 Linux 上的运行;性能基准对比(第 2 项只在用了
StateFrom或StateWithin的元素上多一次祖先查找)。已知的既有失败(和本 PR 无关)
在 main 上运行全量检查时,下面这些本来就失败,本 PR 没有改动它们:
cmd/viva的打包与配方类测试、components的TestDocCatalogCoversEveryComponent、internal/gallery的 OTP 测试、tools/docs、tools/visualparity。