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/9521

Vanessa85570e25df48
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss
index 5dac14ff14..32236af086 100644
--- a/app/src/assets/scss/protyle/_wysiwyg.scss
+++ b/app/src/assets/scss/protyle/_wysiwyg.scss
@@ -382,13 +382,35 @@
opacity: 0;
margin-right: 16px;
background-color: var(--b3-border-color);
+ // 透明覆盖层扩展点击热区,让 4px 的细手柄也能轻松点中
+ position: relative;
z-index: 5;
+ &::before {
+ content: "";
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: -8px;
+ right: -8px;
+ z-index: -1;
+ }
+
&:hover {
opacity: 1;
}
}
+ // 拖拽中的百分比提示(复用 protyle-icon 样式,仅添加定位)
+ > [data-node-id] .sb__resize-tip {
+ position: absolute;
+ top: 0;
+ right: 0;
+ z-index: 10;
+ pointer-events: none;
+ user-select: none;
+ }
+
.sb {
margin-top: 0;
margin-bottom: 0;
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 2a2e8cb0a9..c770e993d8 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -821,10 +821,46 @@ export class WYSIWYG {
previousElement.style.webkitUserModify = "read-only";
// @ts-ignore
nextElement.style.webkitUserModify = "read-only";
+ // 为所有子块创建右上角百分比提示
+ const sbChildren = Array.from(sbElement.querySelectorAll(":scope > [data-node-id]")) as HTMLElement[];
+ const gapHalve = gapPx / 2 + 1;
+ const tips: {el: HTMLElement, child: HTMLElement}[] = [];
+ sbChildren.forEach(child => {
+ child.style.position = "relative";
+ const tip = document.createElement("span");
+ tip.className = "sb__resize-tip protyle-icon";
+ child.appendChild(tip);
+ tips.push({el: tip, child});
+ });
+ // 份额池:每个子块占 100 的整数份额,总和恒为 100
+ // 从子块 style.width 的 calc 百分比恢复,无 width 的用实测宽度估算
+ // 最大余数法取整确保总和精确 = 100,跨拖拽起始显示一致
+ const rawPcts = sbChildren.map(child => {
+ const m = child.style.width.match(/^calc\(([\d.]+)%/);
+ return m ? parseFloat(m[1]) : child.getBoundingClientRect().width / sbWidth * 100;
+ });
+ 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
+ .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++) {
+ shares[remainders[k].i]++;
+ }
+ const leftIdx = sbChildren.indexOf(previousElement);
+ const rightIdx = sbChildren.indexOf(nextElement);
+ const updateTips = () => {
+ tips.forEach(({el}, i) => {
+ el.textContent = `${shares[i]}%`;
+ });
+ };
// 记录最终拖拽宽度,供 mouseup 精确计算百分比,避免从 clientWidth(整数取整)
// 反推导致每次拖拽累积误差
let finalLeft = oldLeftWidth;
let finalRight = oldRightWidth;
+ updateTips();
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
// 左右两块等量交换宽度,不影响其他子块
const delta = moveEvent.clientX - x;
@@ -845,8 +881,21 @@ 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));
+ 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);
+ updateTips();
};
documentSelf.onmouseup = (mouseupEvent) => {
+ tips.forEach(({child, el}) => {
+ el.remove();
+ // 还原 position(若子块原本无 position 则清除)
+ if (!child.getAttribute("style") || child.style.position === "relative") {
+ child.style.position = "";
+ }
+ });
// @ts-ignore
previousElement.style.webkitUserModify = "";
// @ts-ignore
@@ -863,7 +912,6 @@ export class WYSIWYG {
// 只调整左右两块(手柄两侧),其他子块不动,避免影响未拖拽的块
// 使用 mousemove 记录的精确实时宽度(finalLeft/finalRight)反推百分比,
// gapHalve 已含 +1px 余量防止亚像素换行,无需再用 *99 缩放(会造成累积收缩)
- const gapHalve = gapPx / 2 + 1;
let leftPct = Math.round((finalLeft + gapHalve) / sbWidth * 1000) / 10;
let rightPct = Math.round((finalRight + gapHalve) / sbWidth * 1000) / 10;
// 防溢出:两块百分比之和超过 99.5% 时等比压缩到 99%,留 1% 缓冲防换行