Skip to content

Commit

Permalink
🎨 #13568
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 3, 2025
1 parent 866189b commit a78664f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
13 changes: 11 additions & 2 deletions app/src/block/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {focusByWbr, getEditorRange} from "../protyle/util/selection";
import {hasClosestBlock} from "../protyle/util/hasClosest";
import {getTopAloneElement} from "../protyle/wysiwyg/getBlock";
import {genListItemElement, updateListOrder} from "../protyle/wysiwyg/list";
import {transaction, updateTransaction} from "../protyle/wysiwyg/transaction";
import {transaction, turnsIntoOneTransaction, updateTransaction} from "../protyle/wysiwyg/transaction";
import {scrollCenter} from "../util/highlightById";
import {Constants} from "../constants";
import {hideElements} from "../protyle/ui/hideElements";
Expand Down Expand Up @@ -37,7 +37,7 @@ export const cancelSB = (protyle: IProtyle, nodeElement: Element) => {
nodeElement.lastElementChild.remove();
// 超级块中的 html 块需要反转义再赋值 https://github.com/siyuan-note/siyuan/issues/13155
nodeElement.querySelectorAll("protyle-html").forEach(item => {
item.setAttribute("data-content" , item.getAttribute("data-content").replace(/&lt;/g, "<").replace(/&gt;/g, ">"));
item.setAttribute("data-content", item.getAttribute("data-content").replace(/&lt;/g, "<").replace(/&gt;/g, ">"));
});
nodeElement.outerHTML = nodeElement.innerHTML;
return;
Expand Down Expand Up @@ -154,6 +154,15 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id
id: newId,
}]);
}
if (blockElement.parentElement.classList.contains("sb") &&
blockElement.parentElement.getAttribute("data-sb-layout") === "col") {
turnsIntoOneTransaction({
protyle,
selectsElement: position === "afterend" ? [blockElement, blockElement.nextElementSibling] : [blockElement.previousElementSibling, blockElement],
type: "BlocksMergeSuperBlock",
level: "row"
});
}
focusByWbr(protyle.wysiwyg.element, range);
scrollCenter(protyle);
};
Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/util/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ export const clearTableCell = (protyle: IProtyle, tableBlockElement: HTMLElement
}
});
tableSelectElement.removeAttribute("style");
if (getSelection().rangeCount>0) {
if (getSelection().rangeCount > 0) {
const range = getSelection().getRangeAt(0);
if (tableBlockElement.contains(range.startContainer)) {
range.insertNode(document.createElement("wbr"));
Expand Down
9 changes: 9 additions & 0 deletions app/src/protyle/wysiwyg/enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
action: "delete",
id: blockId,
}, undoInsert]);
if (topId === blockId && blockElement.parentElement.classList.contains("sb") &&
blockElement.parentElement.getAttribute("data-sb-layout") === "col") {
turnsIntoOneTransaction({
protyle,
selectsElement: [blockElement.previousElementSibling, blockElement],
type: "BlocksMergeSuperBlock",
level: "row"
});
}
focusByWbr(blockElement, range);
return true;
}
Expand Down
41 changes: 25 additions & 16 deletions app/src/protyle/wysiwyg/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {focusByWbr} from "../util/selection";
import {transaction, updateTransaction} from "./transaction";
import {transaction, turnsIntoOneTransaction, updateTransaction} from "./transaction";
import {genEmptyBlock} from "../../block/util";
import * as dayjs from "dayjs";
import {Constants} from "../../constants";
Expand Down Expand Up @@ -351,8 +351,8 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
}
if (parentLiItemElement.classList.contains("protyle-wysiwyg") || parentLiItemElement.classList.contains("sb") || parentLiItemElement.classList.contains("bq")) {
// 顶层列表
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
const topDoOperations: IOperation[] = [];
const topUndoOperations: IOperation[] = [];
range.collapse(false);
moveToPrevious(deleteElement, range, isDelete);
range.insertNode(document.createElement("wbr"));
Expand All @@ -370,13 +370,13 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
if (!id) {
return;
}
doOperations.push({
topDoOperations.push({
action: "move",
id,
previousID: topPreviousID,
parentID: parentLiItemElement.getAttribute("data-node-id") || protyle.block.parentID
});
undoOperations.push({
topUndoOperations.push({
action: "move",
id,
previousID: index === 1 ? undefined : topPreviousID,
Expand All @@ -401,7 +401,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
lastBlockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
lastBlockElement.innerHTML = `<div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div>`;
previousElement.after(lastBlockElement);
doOperations.push({
topDoOperations.push({
action: "insert",
id: newId,
data: lastBlockElement.outerHTML,
Expand All @@ -410,13 +410,13 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
}
let topOldPreviousID;
while (nextElement && !nextElement.classList.contains("protyle-attr")) {
doOperations.push({
topDoOperations.push({
action: "move",
id: nextElement.getAttribute("data-node-id"),
previousID: topOldPreviousID || lastBlockElement.lastElementChild.previousElementSibling?.getAttribute("data-node-id"),
parentID: lastBlockElement.getAttribute("data-node-id")
});
undoOperations.push({
topUndoOperations.push({
action: "move",
id: nextElement.getAttribute("data-node-id"),
parentID: lastBlockElement.getAttribute("data-node-id"),
Expand All @@ -431,7 +431,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
Array.from(lastBlockElement.children).forEach(orderItem => {
const id = orderItem.getAttribute("data-node-id");
if (id) {
undoOperations.push({
topUndoOperations.push({
action: "update",
id,
data: orderItem.outerHTML,
Expand All @@ -442,7 +442,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
Array.from(lastBlockElement.children).forEach(orderItem => {
const id = orderItem.getAttribute("data-node-id");
if (id) {
doOperations.push({
topDoOperations.push({
action: "update",
id,
data: orderItem.outerHTML,
Expand All @@ -451,7 +451,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
});
}
if (newId) {
undoOperations.push({
topUndoOperations.push({
action: "delete",
id: newId
});
Expand All @@ -464,15 +464,15 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:

if (liElement.childElementCount === 1) {
// 列表只有一项
doOperations.push({
topDoOperations.push({
action: "delete",
id: liId
});
// 聚焦列表,第一个列表项反向缩进后刷新会关闭页签
if (liId === protyle.block.id) {
protyle.block.id = protyle.block.parentID;
}
undoOperations.splice(0, 0, {
topUndoOperations.splice(0, 0, {
action: "insert",
data: movedHTML,
id: liId,
Expand All @@ -484,18 +484,27 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
if (liElement.getAttribute("data-subtype") === "o") {
updateListOrder(liElement, startIndex);
}
doOperations.push({
topDoOperations.push({
action: "update",
id: liId,
data: liElement.outerHTML
});
undoOperations.splice(0, 0, {
topUndoOperations.splice(0, 0, {
action: "update",
id: liId,
data: movedHTML,
});
}
transaction(protyle, doOperations, undoOperations);
transaction(protyle, topDoOperations, topUndoOperations);
if (liElement.childElementCount !== 1 && parentLiItemElement.classList.contains("sb") &&
parentLiItemElement.getAttribute("data-sb-layout") === "col") {
turnsIntoOneTransaction({
protyle,
selectsElement: [liElement, liElement.nextElementSibling],
type: "BlocksMergeSuperBlock",
level: "row"
});
}
focusByWbr(parentLiItemElement, range);
return;
}
Expand Down

0 comments on commit a78664f

Please sign in to comment.