Skip to content

Commit c2bd3d2

Browse files
committed
🎨 #17082
1 parent b22a9a7 commit c2bd3d2

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

app/src/protyle/toolbar/index.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,23 +1104,10 @@ export class Toolbar {
11041104
}
11051105
});
11061106
this.subElementCloseCB = () => {
1107-
if (!renderElement.parentElement || protyle.disabled ||
1108-
(oldTextValue === textElement.value && textElement.value)) {
1109-
if (renderElement.tagName === "SPAN") {
1110-
if (renderElement.parentElement) {
1111-
this.range.setStartAfter(renderElement);
1112-
this.range.collapse(true);
1113-
focusByRange(this.range);
1114-
}
1115-
} else {
1116-
focusBlock(renderElement);
1117-
renderElement.classList.add("protyle-wysiwyg--select");
1118-
}
1119-
protyle.wysiwyg.element.focus({preventScroll: true});
1120-
return;
1121-
}
1107+
const noChange = !renderElement.parentElement || protyle.disabled ||
1108+
(textElement.value && oldTextValue === textElement.value);
11221109
let inlineLastNode: Element;
1123-
if (types.includes("NodeHTMLBlock")) {
1110+
if (types.includes("NodeHTMLBlock") && !noChange) {
11241111
let htmlText = textElement.value;
11251112
if (htmlText) {
11261113
// 需移除首尾的空白字符与连续的换行 (空行) https://github.com/siyuan-note/siyuan/issues/7921
@@ -1131,7 +1118,13 @@ export class Toolbar {
11311118
}
11321119
}
11331120
renderElement.querySelector("protyle-html").setAttribute("data-content", Lute.EscapeHTMLStr(htmlText));
1134-
} else if (isInlineMemo) {
1121+
// HTML 块中包含多个 <pre> 时只能保存第一个 https://github.com/siyuan-note/siyuan/issues/5732
1122+
const tempElement = document.createElement("template");
1123+
tempElement.innerHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
1124+
if (tempElement.content.childElementCount > 1) {
1125+
showMessage(window.siyuan.languages.htmlBlockTip);
1126+
}
1127+
} else if (isInlineMemo && !noChange) {
11351128
let inlineMemoElements;
11361129
if (updateElements) {
11371130
inlineMemoElements = updateElements;
@@ -1162,7 +1155,7 @@ export class Toolbar {
11621155
item.setAttribute("data-inline-memo-content", window.DOMPurify.sanitize(textElement.value));
11631156
}
11641157
});
1165-
} else if (types.includes("inline-math")) {
1158+
} else if (types.includes("inline-math") && !noChange) {
11661159
// 行内数学公式不允许换行 https://github.com/siyuan-note/siyuan/issues/2187
11671160
if (textElement.value) {
11681161
renderElement.setAttribute("data-content", Lute.EscapeHTMLStr(textElement.value));
@@ -1173,7 +1166,7 @@ export class Toolbar {
11731166
// esc 后需要 focus range,但点击空白处不能 focus range,否则光标无法留在点击位置
11741167
renderElement.outerHTML = "<wbr>";
11751168
}
1176-
} else {
1169+
} else if (!noChange) {
11771170
renderElement.setAttribute("data-content", Lute.EscapeHTMLStr(textElement.value));
11781171
renderElement.removeAttribute("data-render");
11791172
if (types.includes("NodeBlockQueryEmbed")) {
@@ -1183,7 +1176,6 @@ export class Toolbar {
11831176
processRender(renderElement);
11841177
}
11851178
}
1186-
11871179
// 光标定位
11881180
if (getSelection().rangeCount === 0 ||
11891181
// $$ 中间输入后再 ESC 光标无法定位
@@ -1204,6 +1196,7 @@ export class Toolbar {
12041196
focusByRange(this.range);
12051197
}
12061198
} else {
1199+
protyle.wysiwyg.element.focus({preventScroll: true});
12071200
focusBlock(renderElement);
12081201
renderElement.classList.add("protyle-wysiwyg--select");
12091202
}
@@ -1212,17 +1205,10 @@ export class Toolbar {
12121205
nodeElement.querySelector("wbr")?.remove();
12131206
}
12141207

1215-
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
1216-
// HTML 块中包含多个 <pre> 时只能保存第一个 https://github.com/siyuan-note/siyuan/issues/5732
1217-
if (types.includes("NodeHTMLBlock")) {
1218-
const tempElement = document.createElement("template");
1219-
tempElement.innerHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
1220-
if (tempElement.content.childElementCount > 1) {
1221-
showMessage(window.siyuan.languages.htmlBlockTip);
1222-
}
1208+
if (!noChange && nodeElement.outerHTML !== html) {
1209+
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
1210+
updateTransaction(protyle, id, nodeElement.outerHTML, html);
12231211
}
1224-
updateTransaction(protyle, id, nodeElement.outerHTML, html);
1225-
protyle.wysiwyg.element.focus({preventScroll: true});
12261212
};
12271213
this.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
12281214
this.subElement.classList.remove("fn__none");

0 commit comments

Comments
 (0)