Skip to content

Commit

Permalink
Merge remote-tracking branch 'forke-siyuan/dev' into v0.35
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Jun 29, 2024
2 parents 6cc7e36 + 85a12a6 commit 13e2f8c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/src/assets/scss/protyle/_wysiwyg.scss
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
border-bottom: 1px solid;
color: var(--b3-protyle-inline-tag-color);
transition: var(--b3-transition);
cursor: pointer; // 预览导出无此元素,只读和编辑状态都需要点击 https://github.com/siyuan-note/siyuan/issues/11854
}

span[data-type~="a"] {
Expand Down Expand Up @@ -601,7 +602,6 @@
// 导出 html 不需要编辑样式
.protyle-wysiwyg[data-readonly="false"] {
span[data-type~="inline-math"],
span[data-type~="tag"],
.protyle-action__language,
.render-node {
cursor: pointer;
Expand Down
8 changes: 5 additions & 3 deletions app/src/menus/protyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
if (inlineTypes.includes("code") || inlineTypes.includes("kbd")) {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.copy,
icon:"iconCopy",
icon: "iconCopy",
click() {
writeText(protyle.lute.BlockDOM2StdMd(inlineElement.outerHTML));
}
Expand Down Expand Up @@ -2092,7 +2092,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
return {menus, removeMenus, insertMenus, otherMenus, other2Menus};
};

export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolean, isRemove?: boolean) => {
export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolean, isRemove?: boolean, addLoading = true) => {
window.sout.tracker("invoked");
if (nodeElement.getAttribute("data-type") === "NodeListItem" && nodeElement.childElementCount < 4) {
// 没有子列表或多个块的列表项不进行折叠
Expand Down Expand Up @@ -2139,7 +2139,9 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
const id = nodeElement.getAttribute("data-node-id");
if (nodeElement.getAttribute("data-type") === "NodeHeading") {
if (hasFold) {
nodeElement.insertAdjacentHTML("beforeend", '<div spin="1" style="text-align: center"><img width="24px" height="24px" src="/stage/loading-pure.svg"></div>');
if (addLoading) {
nodeElement.insertAdjacentHTML("beforeend", '<div spin="1" style="text-align: center"><img width="24px" height="24px" src="/stage/loading-pure.svg"></div>');
}
transaction(protyle, [{
action: "unfoldHeading",
id,
Expand Down
10 changes: 9 additions & 1 deletion app/src/protyle/wysiwyg/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {hasClosestByAttribute, hasClosestByClassName} from "../util/hasClosest";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {headingTurnIntoList, turnIntoTaskList} from "./turnIntoList";
import {updateAVName} from "../render/av/action";
import {setFold} from "../../menus/protyle";

export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: Range, needRender = true, event?: InputEvent) => {
if (!blockElement.parentElement) {
Expand Down Expand Up @@ -64,7 +65,8 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
}
}
const id = blockElement.getAttribute("data-node-id");
if (type !== "NodeCodeBlock" && (editElement.innerHTML.endsWith("\n<wbr>") || editElement.innerHTML.endsWith("\n<wbr>\n"))) {
if ((type !== "NodeCodeBlock" && type !== "NodeHeading") && // https://github.com/siyuan-note/siyuan/issues/11851
(editElement.innerHTML.endsWith("\n<wbr>") || editElement.innerHTML.endsWith("\n<wbr>\n"))) {
// 软换行
updateTransaction(protyle, id, blockElement.outerHTML, protyle.wysiwyg.lastHTMLs[id] || blockElement.outerHTML.replace("\n<wbr>", "<wbr>"));
wbrElement.remove();
Expand Down Expand Up @@ -156,6 +158,12 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
) {
log("SpinBlockDOM", blockElement.outerHTML, "argument", protyle.options.debugger);
log("SpinBlockDOM", html, "result", protyle.options.debugger);
if (blockElement.getAttribute("data-type") === "NodeHeading" && blockElement.getAttribute("fold") === "1" &&
tempElement.content.firstElementChild.getAttribute("data-subtype") !== blockElement.dataset.subtype) {
setFold(protyle, blockElement, undefined, undefined, false);
html = html.replace(' fold="1"', "");
protyle.wysiwyg.lastHTMLs[id] = blockElement.outerHTML;
}
let scrollLeft: number;
if (blockElement.classList.contains("table")) {
scrollLeft = blockElement.firstElementChild.scrollLeft;
Expand Down
7 changes: 4 additions & 3 deletions app/src/protyle/wysiwyg/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ export const turnsIntoTransaction = (options: {
selectsElement.forEach((item, index) => {
if ((options.type === "Blocks2Ps" || options.type === "Blocks2Hs") &&
item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
setFold(options.protyle, item);
setFold(options.protyle, item, undefined, undefined, false);
}
item.classList.remove("protyle-wysiwyg--select");
item.removeAttribute("select-start");
Expand Down Expand Up @@ -1116,18 +1116,20 @@ export const transaction = (protyle: IProtyle, doOperations: IOperation[], undoO
protyle.model.headElement.classList.remove("item--unupdate");
}
protyle.updated = true;

if (needDebounce) {
protyle.undo.replace(doOperations, protyle);
} else {
protyle.undo.add(doOperations, undoOperations, protyle);
}
}
window.clearTimeout(transactionsTimeout);
// 加速折叠 https://github.com/siyuan-note/siyuan/issues/11828
if (doOperations.length === 1 && (
doOperations[0].action === "unfoldHeading" ||
(doOperations[0].action === "setAttrs" && doOperations[0].data.startsWith('{"fold":'))
)) {
// 防止 needDebounce 为 true
protyle.transactionTime = time + Constants.TIMEOUT_INPUT * 2;
fetchPost("/api/transactions", {
session: protyle.id,
app: Constants.SIYUAN_APPID,
Expand Down Expand Up @@ -1168,7 +1170,6 @@ export const transaction = (protyle: IProtyle, doOperations: IOperation[], undoO
});
}
protyle.transactionTime = time;
window.clearTimeout(transactionsTimeout);
transactionsTimeout = window.setTimeout(() => {
promiseTransaction();
}, Constants.TIMEOUT_INPUT * 2);
Expand Down
2 changes: 1 addition & 1 deletion app/src/search/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ ${getAttr(item)}
config.method === 0 ? `<div class="b3-list-item b3-list-item--focus" data-type="search-new">
<svg class="b3-list-item__graphic"><use xlink:href="#iconFile"></use></svg>
<span class="b3-list-item__text">
${window.siyuan.languages.newFile} <mark>${(element.querySelector("#searchInput") as HTMLInputElement).value}</mark>
${window.siyuan.languages.newFile} <mark>${escapeHtml((element.querySelector("#searchInput") as HTMLInputElement).value)}</mark>
</span>
<kbd class="b3-list-item__meta">${window.siyuan.languages.enterNew}</kbd>
</div>
Expand Down

0 comments on commit 13e2f8c

Please sign in to comment.