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

Vanessa4a085df742c6
diff --git a/app/src/assets/scss/protyle/_toolbar.scss b/app/src/assets/scss/protyle/_toolbar.scss
index eb3121e72e..a588d6bd8b 100644
--- a/app/src/assets/scss/protyle/_toolbar.scss
+++ b/app/src/assets/scss/protyle/_toolbar.scss
@@ -90,8 +90,7 @@
// 行号栏与文本域共同的滚动容器,二者同高,由父层统一滚动,避免 JS 同步滚动
&__scroll {
overflow: auto;
- flex: 1;
- min-height: 0;
+ width: 100%;
border-radius: 0 0 var(--b3-border-radius-b) var(--b3-border-radius-b);
}
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 97d3900f8c..75280deb92 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -965,6 +965,10 @@ export class Toolbar {
this.subElement.style.padding = "0";
this.subElement.style.display = "flex";
this.subElement.style.flexDirection = "column";
+ if (!isMobile()) {
+ // 初始宽度由面板决定,滚动区与文本域 width:100% 跟随,拖拽缩放后由 moveResize 改写面板宽度
+ this.subElement.style.width = Math.max(480, renderElement.clientWidth * 0.7) + "px";
+ }
this.subElement.innerHTML = `<div class="fn__flex-column"><div class="block__icons block__icons--menu fn__flex" style="border-radius: var(--b3-border-radius-b) var(--b3-border-radius-b) 0 0;">
<span class="fn__flex-1 resize__move" style="line-height: 24px;">
${title}
@@ -982,30 +986,30 @@ export class Toolbar {
<span class="fn__space"></span>
<button data-type="close" class="block__icon block__icon--show b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.close}"><svg><use xlink:href="#iconClose"></use></svg></button>
</div>
-<div class="protyle-util__scroll"><div class="fn__flex"><div class="protyle-linenumber__rows"></div><textarea ${protyle.disabled ? " readonly" : ""} spellcheck="false" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${placeholder}" style="resize:none;font-family: var(--b3-font-family-code);${isMobile() ? "" : "width:" + Math.max(480, renderElement.clientWidth * 0.7) + "px"}"></textarea></div></div></div>
+<div class="protyle-util__scroll"><div class="fn__flex"><div class="protyle-linenumber__rows"></div><textarea ${protyle.disabled ? " readonly" : ""} spellcheck="false" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${placeholder}" style="resize:none;font-family: var(--b3-font-family-code);"></textarea></div></div></div>
<div class="resize__rd"></div><div class="resize__ld"></div><div class="resize__lt"></div><div class="resize__rt"></div><div class="resize__r"></div><div class="resize__d"></div><div class="resize__t"></div><div class="resize__l"></div>`;
const gutter = this.subElement.querySelector(".protyle-linenumber__rows") as HTMLElement;
const renderTextareaLineNumber = () => {
// textarea 末尾的 \n 视觉上会占一行空行,行号需保留该空行,故不去除末尾空串
const lineList = textElement.value.split(/\r\n|\r|\n/);
- // 先用占位 span 撑出行号栏宽度,便于同步 textarea 左内边距
- gutter.innerHTML = `<span></span>${"<span></span>".repeat(Math.max(0, lineList.length - 1))}`;
- // 行号栏宽度随数字位数变化,需同步 textarea 左内边距避免文字被遮挡
- const gutterWidth = gutter.clientWidth;
// textarea 默认软换行,需用镜像元素测量每个源码行折行后的实际高度,行号才能与可视行对齐
const textCs = window.getComputedStyle(textElement);
const mirror = document.createElement("div");
mirror.style.position = "absolute";
mirror.style.visibility = "hidden";
mirror.style.whiteSpace = "pre-wrap";
- mirror.style.wordBreak = textCs.wordBreak || "break-word";
+ // textarea 的软换行接近 overflow-wrap: break-word,而非 word-break,否则长标识符断点不一致
+ mirror.style.overflowWrap = "break-word";
+ mirror.style.wordBreak = "normal";
+ mirror.style.tabSize = textCs.tabSize;
mirror.style.fontFamily = textCs.fontFamily;
mirror.style.fontSize = textCs.fontSize;
mirror.style.lineHeight = textCs.lineHeight;
mirror.style.fontWeight = textCs.fontWeight;
mirror.style.fontVariantLigatures = textCs.fontVariantLigatures;
- // 宽度需与 textarea 文本区一致(去掉左右内边距,textarea 无边框)
- mirror.style.width = textElement.clientWidth - gutterWidth - 8 - parseInt(textCs.paddingRight) + "px";
+ mirror.style.letterSpacing = textCs.letterSpacing;
+ // 宽度需与 textarea 文本区一致:clientWidth 减去左右内边距
+ mirror.style.width = textElement.clientWidth - parseInt(textCs.paddingLeft) - parseInt(textCs.paddingRight) + "px";
mirror.style.boxSizing = "border-box";
mirror.style.padding = "0";
mirror.innerHTML = lineList.map(line => `<div>${line.trim() ? escapeHtml(line) : "&nbsp;"}</div>`).join("");