diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 3d43971c0..e74491ccd 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -380,7 +380,7 @@ export class Gutter { this.renderMenu(protyle, buttonElement); // https://ld246.com/article/1648433751993 if (!protyle.toolbar.range) { - protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element.firstElementChild); + protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`) || protyle.wysiwyg.element.firstElementChild); } /// #if MOBILE window.siyuan.menus.menu.fullscreen(); @@ -418,7 +418,9 @@ export class Gutter { } else if (buttonElement.dataset.type !== "NodeAttributeViewRow") { this.renderMenu(protyle, buttonElement); if (!protyle.toolbar.range) { - protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element.firstElementChild); + protyle.toolbar.range = getEditorRange( + protyle.wysiwyg.element.querySelector(`[data-node-id="${buttonElement.getAttribute("data-node-id")}"]`) || + protyle.wysiwyg.element.firstElementChild); } /// #if MOBILE window.siyuan.menus.menu.fullscreen(); @@ -1382,9 +1384,11 @@ export class Gutter { id: "separator_cancelSuperBlock", type: "separator" }).element); + const isCol = nodeElement.getAttribute("data-sb-layout") === "col"; window.siyuan.menus.menu.append(new MenuItem({ id: "cancelSuperBlock", label: window.siyuan.languages.cancel + " " + window.siyuan.languages.superBlock, + accelerator: window.siyuan.config.keymap.editor.general[isCol ? "hLayout" : "vLayout"].custom, click() { const sbData = cancelSB(protyle, nodeElement); transaction(protyle, sbData.doOperations, sbData.undoOperations); @@ -1392,6 +1396,22 @@ export class Gutter { hideElements(["gutter"], protyle); } }).element); + window.siyuan.menus.menu.append(new MenuItem({ + accelerator: window.siyuan.config.keymap.editor.general[isCol ? "vLayout" : "hLayout"].custom, + label: window.siyuan.languages.turnInto + " " + window.siyuan.languages[isCol ? "vLayout" : "hLayout"], + click() { + const oldHTML = nodeElement.outerHTML; + if (isCol) { + nodeElement.setAttribute("data-sb-layout", "row") + } else { + nodeElement.setAttribute("data-sb-layout", "col") + } + nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); + updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML); + focusByRange(protyle.toolbar.range); + hideElements(["gutter"], protyle); + } + }).element); } else if (type === "NodeCodeBlock" && !protyle.disabled && !nodeElement.getAttribute("data-subtype")) { window.siyuan.menus.menu.append(new MenuItem({id: "separator_code", type: "separator"}).element); const linewrap = nodeElement.getAttribute("linewrap"); diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index dd089bc60..ce7c1924e 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -35,6 +35,7 @@ import {matchHotKey} from "../util/hotKey"; import {enter, softEnter} from "./enter"; import {clearTableCell, fixTable} from "../util/table"; import { + transaction, turnsIntoOneTransaction, turnsIntoTransaction, turnsOneInto, @@ -44,7 +45,7 @@ import { import {fontEvent} from "../toolbar/Font"; import {addSubList, listIndent, listOutdent} from "./list"; import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename"; -import {insertEmptyBlock, jumpToParent} from "../../block/util"; +import {cancelSB, insertEmptyBlock, jumpToParent} from "../../block/util"; import {isLocalPath} from "../../util/pathName"; /// #if !MOBILE import {openBy, openFileById} from "../../editor/util"; @@ -1565,6 +1566,20 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { event.preventDefault(); event.stopPropagation(); const selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); + if (selectsElement.length === 1 && selectsElement[0].getAttribute("data-type") === "NodeSuperBlock") { + if (selectsElement[0].getAttribute("data-sb-layout") === "col") { + const oldHTML = selectsElement[0].outerHTML; + selectsElement[0].setAttribute("data-sb-layout", "row") + selectsElement[0].setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); + updateTransaction(protyle, selectsElement[0].getAttribute("data-node-id"), selectsElement[0].outerHTML, oldHTML); + } else { + range.insertNode(document.createElement("wbr")) + const sbData = cancelSB(protyle, selectsElement[0]); + transaction(protyle, sbData.doOperations, sbData.undoOperations); + focusByWbr(protyle.wysiwyg.element, range) + } + return; + } if (selectsElement.length < 2 || selectsElement[0]?.classList.contains("li")) { return; } @@ -1580,6 +1595,20 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { event.preventDefault(); event.stopPropagation(); const selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); + if (selectsElement.length === 1 && selectsElement[0].getAttribute("data-type") === "NodeSuperBlock") { + if (selectsElement[0].getAttribute("data-sb-layout") === "row") { + const oldHTML = selectsElement[0].outerHTML; + selectsElement[0].setAttribute("data-sb-layout", "col") + selectsElement[0].setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); + updateTransaction(protyle, selectsElement[0].getAttribute("data-node-id"), selectsElement[0].outerHTML, oldHTML); + } else { + range.insertNode(document.createElement("wbr")) + const sbData = cancelSB(protyle, selectsElement[0]); + transaction(protyle, sbData.doOperations, sbData.undoOperations); + focusByWbr(protyle.wysiwyg.element, range) + } + return; + } if (selectsElement.length < 2 || selectsElement[0]?.classList.contains("li")) { return; }