Skip to content

Commit

Permalink
🎨 #13664
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 5, 2025
1 parent 4ed38f2 commit b9eeaa1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
24 changes: 22 additions & 2 deletions app/src/protyle/gutter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1382,16 +1384,34 @@ 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);
focusBlock(protyle.wysiwyg.element.querySelector(`[data-node-id="${sbData.previousId}"]`));
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");
Expand Down
31 changes: 30 additions & 1 deletion app/src/protyle/wysiwyg/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit b9eeaa1

Please sign in to comment.