实现收藏文本长文本折叠/展开/复制、收藏搜索关键词高亮

需求7.4两处此前完全没接:文本收藏是不限高度的纯<p>,长文本不折叠、
没有展开/收起,也没有复制按钮;收藏搜索的query从未传到文本收藏这一
层,History那边已有的Highlight组件在Favorites里从未被引用(实测:
搜索一个真实命中的关键词,结果列表0个<mark>)。

新增FavoriteText组件:用scrollHeight/clientHeight判断是否真的溢出
(避免给短文本也显示无用的"展开"按钮),复制走和context-menu.jsx
的copyMessageText一致的navigator.clipboard.writeText。

-webkit-line-clamp在当前环境对这个<p>不生效(getComputedStyle能读到
设置值但视觉不裁切),改用line-height反推的max-height+overflow:hidden;
外层容器不能用display:flex,会被UA blockify成flow-root导致同样失效。

第十二轮最小粒度测试 Ch7 发现,已用真实浏览器验证展开/收起切换正常、
搜索关键词高亮正确命中。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-09-06 05:30:40 +08:00
co-authored by Claude Sonnet 5
parent cccd21aff1
commit 6882103461
3 changed files with 77 additions and 4 deletions
+46
View File
@@ -10986,6 +10986,52 @@ div.toast.show {
line-height: 1.65;
}
/* 需求7.4"长文本折叠、展开和复制":clamped 限定默认显示高度,展开态(FavoriteText 的
expanded=true) 去掉这个 class 即可显示全文;library-text-actions 放"展开/收起"(仅溢出
时才渲染)和"复制"两个按钮,颜色沿用应用里其它文字按钮的强调色。
没有用 -webkit-line-clamp:实测这个环境里它对这个 <p> 不生效——getComputedStyle 能读到
display/-webkit-line-clamp/overflow 都是设置的值,但视觉上完全不裁切,scrollHeight 也跟
clientHeight 相等,是那套盒模型本身在当前渲染环境下没有实际生效,不是 CSS 写错了。改用
.library-text-content 已有的 line-height:1.65 反推的 max-height(5 行 = 5*1.65em)+
overflow:hidden,是普通块级盒子,不依赖任何厂商前缀的特殊渲染路径,行为可预期。 */
.library-text-content.clamped {
max-height: 8.25em;
overflow: hidden;
}
/* library-text-wrap 故意不用 display:flex——曾经这样写过,结果 .clamped 的 <p> 变成了 flex
item:flex/grid item 的 specified display 会被 UA 按 CSS Display 规范"blockify",实测这里的
-webkit-box 被换成了 flow-root(getComputedStyle 验证过),-webkit-line-clamp 整个失效,折叠
彻底不生效。改回普通块级 + margin 做间距,让 .clamped 保持自己声明的 -webkit-box 不被更外层
的 flex 容器改写。 */
.library-text-wrap {
display: block;
}
.library-text-actions {
display: flex;
align-items: center;
gap: 1.1rem;
margin-top: 0.35rem;
}
.library-text-actions button {
display: inline-flex;
align-items: center;
gap: 0.2rem;
margin: 0;
padding: 0;
border: 0;
box-shadow: none;
background: transparent;
color: #3b82c4;
font-size: 0.82rem;
}
.library-text-actions button .material-icons {
font-size: 1rem;
}
.library-file-card {
display: grid;
grid-template-columns: 3rem minmax(0, 1fr) auto;
+1 -1
View File
File diff suppressed because one or more lines are too long