fix(editor): 修复文章页折叠行被撑高 & 折叠图标垂直不居中

文章页 CodeRunner 嵌在 .md-content 内,CodeMirror 折叠后插入的
<img class="cm-widgetBuffer">(width:0、height:1em 的占位符,用于对齐折叠
widget 基线)被 .md-content img 的 margin:1rem 0 命中,上下各 16px margin
把折叠那行 .cm-line 撑到 47.5px(试运行页不在 .md-content 内,正常 19.6px)。
对比两页 .cm-line 的 children 锁定:文章页含 cm-widgetBuffer,试运行页没有。

input.css:.md-content img 选择器加 :where(:not(.cm-widgetBuffer)) 排除占位 img,
用 :where() 压低特异性避免影响其它规则。

themes.ts:core 对折叠列 .cm-foldGutter .cm-gutterElement 完全没设样式,格子
高度 ≈ font-size(14px) 比正文行(line-height ≈19.6px)矮,图标偏离中央。给格子
flex 居中 + line-height:1.4(复刻 CM 的字号×1.4 行高算法),图标落在正文行中央。
This commit is contained in:
xfy 2026-07-08 14:03:14 +08:00
parent 20540358c2
commit 5b9e65bf72
2 changed files with 21 additions and 10 deletions

View File

@ -444,7 +444,11 @@
background: var(--color-paper-entry);
}
.md-content img {
/* 排除 CodeMirror 编辑器内的 <img>CM <img class="cm-widgetBuffer">width:0
height:1em 的占位符对齐折叠 widget 的基线若被这里的 margin/height 命中
会把折叠那行 .cm-line 撑高约 32px上下各 1rem margin :where()
.cm-editor 后代的 img 优先级压到 0确保 CM 内部任何 img 都不受正文图片样式影响 */
.md-content img:where(:not(.cm-widgetBuffer)) {
border-radius: var(--radius-paper);
margin: 1rem 0;
max-width: 100%;

View File

@ -29,23 +29,30 @@ const gutterBackgroundOverride: Extension = EditorView.theme({
});
/**
* CodeMirror fold gutter /
* CodeMirror fold gutter /
*
* core baseTheme@codemirror/language `.cm-foldGutter span`
* `padding`/`cursor` `display`/`vertical-align` <span>
* `.cm-gutterElement` core 线
*
* core baseTheme `.cm-gutterElement` `box-sizing`
* `.cm-foldGutter .cm-gutterElement` `.cm-gutter`
* `display:flex; flex-direction:column`
* font-size14pxline-height 19.6px
* /
*
* editor.ts 线 ``(U+2304)/``(U+203A)
* ``(U+25BE)/``(U+25B8) flex
* `.cm-foldGutter`
* 线
* flex
* .cm-line line-height CodeMirror
* × 1.4 14px 19.6px
*
*
* 47.5px vs 19.6px
* placeholder `<img class="cm-widgetBuffer">` `.md-content img`
* `margin: 1rem 0` 16px = 32px input.css
* `.md-content img:where(:not(.cm-widgetBuffer))`
*/
const foldGutterCenterOverride: Extension = EditorView.theme({
'.cm-foldGutter .cm-gutterElement': {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
lineHeight: '1.4',
},
});