fix(codemirror): 编辑器塌缩导致上下背景割裂(height:100% 失效)

上一提交(3c10f72)用 `& { height: 100% }` 让 .cm-editor 撑满容器,
但实测无效——headless chromium 抓取 computed style 显示:

  容器#ed:      h=280px  (min-height)
  .cm-editor:   h=63px   ← 塌缩!只有内容高度
  .cm-gutters:  h=63px
  .cm-content:  h=63px

根因:CSS 百分比高度要求父元素有「明确 height」(不是 min-height)。
容器只有 min-height: 280px,没有 height,`.cm-editor { height: 100% }`
解析为 auto,塌缩到内容高度(3 行 ≈ 63px)。剩余 217px 透出容器背景
(paper-entry/mantle),与 .cm-editor 的 base 色形成上下割裂。

修复:改用 flexbox 而非百分比高度——
- themes.ts:`& { flex: 1 1 0; minHeight: 0 }`(替换 height:100%)
- 容器(system.rs / runner.rs):`display: flex; flex-direction: column`

flex 子项的 `flex: 1` 不依赖父元素 height,能真正填满 min-height 撑开
的空间。headless 验证:.cm-editor 现为 280px,与容器一致,割裂消失。

诊断方法:构建自包含测试 HTML(内联 editor.js),chromium --headless
--dump-dom 抓 getComputedStyle。这是应有的反馈循环,避免了前几轮
凭代码猜测导致的反复误诊。
This commit is contained in:
xfy 2026-07-06 00:20:55 +08:00
parent b207babdb6
commit d3c2e41fd8
3 changed files with 10 additions and 7 deletions

View File

@ -13,13 +13,15 @@ export type ThemeName = 'light' | 'dark';
* `#333338` catppuccin `.cm-gutters`catppuccin base
* `!important` editor base
*
* 2. `.cm-editor` core `&` height
*
* `& { height: 100% }`
* 2. `.cm-editor` core `&` height/flex
* `height: 100%` min-height CSS
* height `flex: 1` `display: flex`
*
*/
const gutterBackgroundOverride: Extension = EditorView.theme({
'&': {
height: '100%',
flex: '1 1 0',
minHeight: '0',
},
'.cm-gutters': {
backgroundColor: 'transparent !important',

View File

@ -245,7 +245,7 @@ pub fn CodeRunner(
div {
id: "{container_id}",
class: "code-runner-editor font-mono text-sm",
style: "min-height: 160px",
style: "min-height: 160px; display: flex; flex-direction: column",
}
// 输出区
if !output().is_empty() {

View File

@ -910,10 +910,11 @@ fn SqlConsoleTab() -> Element {
}
span { class: "text-xs text-[var(--color-paper-tertiary)] font-mono", "⌘↵ 执行" }
}
// CodeMirror 容器
// CodeMirror 容器:用 flex 让 .cm-editor(flex:1) 填满整个高度,
// 避免编辑器塌缩到内容高度、底部透出容器背景造成上下色差。
div {
id: "sql-editor",
style: "min-height: 280px",
style: "min-height: 280px; display: flex; flex-direction: column",
}
}