mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
This commit is contained in:
parent
147d083770
commit
d41f148d9c
1 changed files with 6 additions and 7 deletions
|
|
@ -91,11 +91,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
|
||||||
if (!isPreview && (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum))) {
|
if (!isPreview && (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum))) {
|
||||||
// 需要先添加 class 以防止抖动 https://ld246.com/article/1648116585443
|
// 需要先添加 class 以防止抖动 https://ld246.com/article/1648116585443
|
||||||
block.classList.add("protyle-linenumber");
|
block.classList.add("protyle-linenumber");
|
||||||
setTimeout(() => {
|
lineNumberRender(block);
|
||||||
// windows 需等待字体下载完成再计算,否则导致不换行,高度计算错误
|
|
||||||
// https://github.com/siyuan-note/siyuan/issues/9029
|
|
||||||
lineNumberRender(block);
|
|
||||||
}, block.getAttribute("contenteditable") === "true" ? 0 : Constants.TIMEOUT_DBLCLICK);
|
|
||||||
if (languageElement) {
|
if (languageElement) {
|
||||||
languageElement.style.marginLeft = "3.6em";
|
languageElement.style.marginLeft = "3.6em";
|
||||||
}
|
}
|
||||||
|
|
@ -152,8 +148,11 @@ export const lineNumberRender = (block: HTMLElement) => {
|
||||||
let lineHeight = "";
|
let lineHeight = "";
|
||||||
if (isWrap) {
|
if (isWrap) {
|
||||||
lineNumberTemp.textContent = line || "\n";
|
lineNumberTemp.textContent = line || "\n";
|
||||||
const height = lineNumberTemp.getBoundingClientRect().height.toFixed(1);
|
// 不能使用 lineNumberTemp.getBoundingClientRect().height.toFixed(1) 否则
|
||||||
lineHeight = ` style="height:${height}px;"`;
|
// windows 需等待字体下载完成再计算,否则导致不换行,高度计算错误
|
||||||
|
// https://github.com/siyuan-note/siyuan/issues/9029
|
||||||
|
// https://github.com/siyuan-note/siyuan/issues/9140
|
||||||
|
lineHeight = ` style="height:${lineNumberTemp.clientHeight}px;"`;
|
||||||
}
|
}
|
||||||
lineNumberHTML += `<span${lineHeight}></span>`;
|
lineNumberHTML += `<span${lineHeight}></span>`;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue