diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 1f2a281..2c2e05b 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -1667,6 +1667,8 @@ body.pv-max .pv-pre { max-width: none; } /* 放大时源码面板同样铺满 */ counter-reset: pvline; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4; } /* 单行:行号用 ::before + counter 生成。伪元素不参与选区,复制代码时不会把行号带进去 */ .pv-cl { display: flex; min-height: 1.6em; counter-increment: pvline; white-space: pre; padding-right: 12px; } +/* 代码必须落在显式元素里:flex 容器的裸文本是匿名 flex 项,前导空白会被折叠、纯缩进行会被丢掉 */ +.pv-cl .c { flex: 1 0 auto; white-space: pre; } .pv-cl::before { content: counter(pvline); flex: none; width: calc(var(--nw, 3ch) + 18px); margin-right: 10px; padding-right: 8px; text-align: right; color: #b0b6bd; user-select: none; @@ -1746,8 +1748,12 @@ body.pv-max .pv-code { max-width: none; padding-left: 16px; padding-right: 16px; .vcs-stat .d { color: #cf222e; } .vcs-fb { display: none; border-top: 1px solid var(--border); overflow-x: auto; background: #fff; } .vcs-file.open .vcs-fb { display: block; } +/* 滚动内容包一层:inline-block 的宽度由内容决定(max-content),行再撑满它。 + 否则块级行只有容器宽,横向滚动后短行右侧露白,红绿底色盖不住 */ +.vcs-fb-in { display: block; min-width: 100%; } /* 行:旧号 / 新号 / 代码三列。代码不换行,横向滚动(diff 语义上就该逐行对齐) */ .vcs-line { display: grid; grid-template-columns: 44px 44px minmax(0, 1fr); + width: 100%; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; } .vcs-line .n { padding: 0 6px; text-align: right; color: #b0b6bd; user-select: none; background: #fafbfc; border-right: 1px solid rgba(0,0,0,.04); } diff --git a/app/server/public/js/preview.js b/app/server/public/js/preview.js index b224a90..63c9c5c 100644 --- a/app/server/public/js/preview.js +++ b/app/server/public/js/preview.js @@ -564,8 +564,9 @@ async function pvTextNode(name, sizeText, r) { const parts = hl ? pvSplitHighlighted(hl) : null; const useHl = parts && parts.length === shown.length; // 行数对不上就退回纯文本,不让行号错位 for (let i = 0; i < shown.length; i++) { - // 行号交给 CSS counter(.pv-cl::before)生成:伪元素不进选区,复制不会把行号带走 - rows.push('
' + (useHl ? parts[i] : esc(shown[i])) + '
'); + // 行号交给 CSS counter(.pv-cl::before)生成:伪元素不进选区,复制不会把行号带走。 + // 代码必须包在 .c 里:裸文本在 flex 容器里是匿名 flex 项,浏览器会折叠它的前导空白。 + rows.push('
' + (useHl ? parts[i] : esc(shown[i])) + '
'); } code.innerHTML = rows.join(''); frag.appendChild(code); diff --git a/app/server/public/js/vcs.js b/app/server/public/js/vcs.js index fb9304d..add314a 100644 --- a/app/server/public/js/vcs.js +++ b/app/server/public/js/vcs.js @@ -130,10 +130,21 @@ '' + esc(BADGE[f.status] || f.status) + '' + '+' + f.adds + '-' + f.dels + '' + '' + - '
' + patchHtml(f) + (f.truncated ? '
差异过大,已截断
' : '') + '
' + + '
' + patchHtml(f) + (f.truncated ? '
差异过大,已截断
' : '') + '
' + ''; } + // 行背景要盖满「可视宽度 ∩ 内容宽度」:只量 clientWidth 不够,长行溢出到 1129 时行背景仍只有 699, + // 横滑右边就露白。scrollWidth 正好是最长行的内容宽,取两者较大值写成 px 给内层。 + function syncPatchWidth(scope) { + (scope || document).querySelectorAll('.vcs-fb').forEach(function (fb) { + const inner = fb.firstElementChild; + if (!inner) return; + const w = Math.max(fb.clientWidth, fb.scrollWidth); + if (w > 0) inner.style.minWidth = w + 'px'; + }); + } + function renderDetail(d) { st.cur = d; const openAll = d.files.length <= 3; // 少量文件默认展开,多文件默认折叠 @@ -157,6 +168,7 @@ if (!d.files.length) parts.push('
没有文件变动
'); parts.push(''); bodyEl().innerHTML = parts.join(''); + syncPatchWidth(bodyEl()); } // ---------- 数据加载 ---------- @@ -248,7 +260,7 @@ const back = e.target.closest('.vcs-back'); if (back) { loadList(false); return; } const fh = e.target.closest('.vcs-fh'); - if (fh) { fh.parentNode.classList.toggle('open'); return; } + if (fh) { fh.parentNode.classList.toggle('open'); syncPatchWidth(fh.parentNode); return; } }); window.openVcsPane = openPane;