fix(ui): 代码预览的缩进空白被吃掉,Git diff 横向滚动时行背景露白
两个渲染层的坑: 1) 代码预览每行是 <div class="pv-cl"> 直接放文本节点,而 .pv-cl 是 display:flex,裸文本成了匿名 flex 项——浏览器会折叠它的前导空白,整行 只有缩进时该文本节点直接被当成「flex 项之间的空白」丢掉。现在代码包进 显式的 <span class="c">,.c 上 white-space: pre,缩进和 tab 都回来了。 2) Git diff 的行背景只到可视宽度:块级元素在 overflow-x 容器里宽度恒为 容器宽,内容溢出时背景不跟着延伸,横滑后短行右侧一片白。滚动区里包一层 .vcs-fb-in,行 width:100% 撑满它,宽度用 syncPatchWidth() 实测—— Math.max(clientWidth, scrollWidth),只量 clientWidth 会漏掉最长行的内容宽 (实测 699 vs 1129,13 行全部按 1129 铺开)。渲染详情与展开文件时各同步一次。
This commit is contained in:
@@ -130,10 +130,21 @@
|
||||
'<span class="vcs-badge ' + esc(String(f.status || '').toLowerCase()) + '">' + esc(BADGE[f.status] || f.status) + '</span>' +
|
||||
'<span class="vcs-stat"><b class="a">+' + f.adds + '</b><b class="d">-' + f.dels + '</b></span>' +
|
||||
'</div>' +
|
||||
'<div class="vcs-fb">' + patchHtml(f) + (f.truncated ? '<div class="vcs-nodiff">差异过大,已截断</div>' : '') + '</div>' +
|
||||
'<div class="vcs-fb"><div class="vcs-fb-in">' + patchHtml(f) + (f.truncated ? '<div class="vcs-nodiff">差异过大,已截断</div>' : '') + '</div></div>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
// 行背景要盖满「可视宽度 ∩ 内容宽度」:只量 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('<div class="vcs-empty">没有文件变动</div>');
|
||||
parts.push('</div>');
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user