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:
parent
b207babdb6
commit
d3c2e41fd8
@ -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',
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user