Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/18161

Vanessad4957c7fb01f
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 28b32d0121..f8327e735a 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -836,7 +836,7 @@ export class WYSIWYG {
child.appendChild(tip);
tips.push({el: tip, child});
});
- // 份额池:每个子块占 100 的整数份额,总和恒为 100
+ // 份额池:每个子块占 100 的份额(一位小数),总和恒为 100
// 从子块 style.width 的 calc 百分比恢复,无 width 的用实测宽度估算
// 最大余数法取整确保总和精确 = 100,跨拖拽起始显示一致
const rawPcts = sbChildren.map(child => {
@@ -845,9 +845,11 @@ export class WYSIWYG {
});
const totalRaw = rawPcts.reduce((s, p) => s + p, 0) || 1;
const normalized = rawPcts.map(p => p / totalRaw * 100);
- const shares = normalized.map(p => Math.floor(p));
- const deficit = 100 - shares.reduce((s, p) => s + p, 0);
- const remainders = normalized
+ // 以 0.1 为最小单位(×10 后取整),最大余数法分配,再 /10 回到一位小数
+ const scaled = normalized.map(p => p * 10);
+ const shares = scaled.map(p => Math.floor(p));
+ const deficit = 1000 - shares.reduce((s, p) => s + p, 0);
+ const remainders = scaled
.map((p, i) => ({i, frac: p - Math.floor(p)}))
.sort((a, b) => b.frac - a.frac);
for (let k = 0; k < deficit && k < remainders.length; k++) {
@@ -857,7 +859,7 @@ export class WYSIWYG {
const rightIdx = sbChildren.indexOf(nextElement);
const updateTips = () => {
tips.forEach(({el}, i) => {
- el.textContent = `${shares[i]}%`;
+ el.textContent = `${(shares[i] / 10).toFixed(1)}%`;
});
};
// 记录最终拖拽宽度,供 mouseup 精确计算百分比,避免从 clientWidth(整数取整)
@@ -885,11 +887,11 @@ export class WYSIWYG {
previousElement.style.flex = "none";
nextElement.style.width = newRightWidth + "px";
nextElement.style.flex = "none";
- // 更新份额池:左块份额 = 当前宽度占比 × 100(整数),右块 = 100 - 左块 - 其他块份额
- const newLeftShare = Math.max(1, Math.round(newLeftWidth / sbWidth * 100));
+ // 更新份额池:左块份额 = 当前宽度占比 × 1000(一位小数精度),右块 = 1000 - 左块 - 其他块份额
+ const newLeftShare = Math.max(1, Math.round(newLeftWidth / sbWidth * 1000));
const othersSum = shares.reduce((s, p, i) => i === leftIdx || i === rightIdx ? s : s + p, 0);
shares[leftIdx] = newLeftShare;
- shares[rightIdx] = Math.max(1, 100 - othersSum - newLeftShare);
+ shares[rightIdx] = Math.max(1, 1000 - othersSum - newLeftShare);
updateTips();
};
documentSelf.onmouseup = (mouseupEvent) => {