mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
This commit is contained in:
parent
125fd486cc
commit
5f73ce9a24
3 changed files with 72 additions and 47 deletions
|
|
@ -4,7 +4,13 @@ import {iframeMenu, setFold, tableMenu, videoMenu, zoomOut} from "../../menus/pr
|
||||||
import {MenuItem} from "../../menus/Menu";
|
import {MenuItem} from "../../menus/Menu";
|
||||||
import {copySubMenu, openAttr, openWechatNotify} from "../../menus/commonMenuItem";
|
import {copySubMenu, openAttr, openWechatNotify} from "../../menus/commonMenuItem";
|
||||||
import {updateHotkeyTip, writeText} from "../util/compatibility";
|
import {updateHotkeyTip, writeText} from "../util/compatibility";
|
||||||
import {transaction, turnIntoTransaction, turnsIntoTransaction, updateTransaction} from "../wysiwyg/transaction";
|
import {
|
||||||
|
transaction,
|
||||||
|
turnIntoTransaction,
|
||||||
|
turnsIntoTransaction,
|
||||||
|
updateBatchTransaction,
|
||||||
|
updateTransaction
|
||||||
|
} from "../wysiwyg/transaction";
|
||||||
import {removeBlock} from "../wysiwyg/remove";
|
import {removeBlock} from "../wysiwyg/remove";
|
||||||
import {focusBlock, focusByRange, getEditorRange} from "../util/selection";
|
import {focusBlock, focusByRange, getEditorRange} from "../util/selection";
|
||||||
import {hideElements} from "../ui/hideElements";
|
import {hideElements} from "../ui/hideElements";
|
||||||
|
|
@ -1157,24 +1163,7 @@ export class Gutter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private genClick(nodeElements: Element[], protyle: IProtyle, cb: (e: HTMLElement) => void) {
|
private genClick(nodeElements: Element[], protyle: IProtyle, cb: (e: HTMLElement) => void) {
|
||||||
const operations: IOperation[] = [];
|
updateBatchTransaction(nodeElements, protyle, cb);
|
||||||
const undoOperations: IOperation[] = [];
|
|
||||||
nodeElements.forEach((element) => {
|
|
||||||
const id = element.getAttribute("data-node-id");
|
|
||||||
element.classList.remove("protyle-wysiwyg--select");
|
|
||||||
undoOperations.push({
|
|
||||||
action: "update",
|
|
||||||
id,
|
|
||||||
data: element.outerHTML
|
|
||||||
});
|
|
||||||
cb(element as HTMLElement);
|
|
||||||
operations.push({
|
|
||||||
action: "update",
|
|
||||||
id,
|
|
||||||
data: element.outerHTML
|
|
||||||
});
|
|
||||||
});
|
|
||||||
transaction(protyle, operations, undoOperations);
|
|
||||||
focusBlock(nodeElements[0]);
|
focusBlock(nodeElements[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,13 @@ import {
|
||||||
import {matchHotKey} from "../util/hotKey";
|
import {matchHotKey} from "../util/hotKey";
|
||||||
import {enter} from "./enter";
|
import {enter} from "./enter";
|
||||||
import {fixTable} from "../util/table";
|
import {fixTable} from "../util/table";
|
||||||
import {phTransaction, transaction, turnsIntoTransaction, updateTransaction} from "./transaction";
|
import {
|
||||||
|
phTransaction,
|
||||||
|
transaction,
|
||||||
|
turnsIntoTransaction,
|
||||||
|
updateBatchTransaction,
|
||||||
|
updateTransaction
|
||||||
|
} from "./transaction";
|
||||||
import {fontEvent} from "../toolbar/Font";
|
import {fontEvent} from "../toolbar/Font";
|
||||||
import {listIndent, listOutdent, updateListOrder} from "./list";
|
import {listIndent, listOutdent, updateListOrder} from "./list";
|
||||||
import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
|
import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
|
||||||
|
|
@ -960,46 +966,55 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignLeft.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignLeft.custom, event)) {
|
||||||
let actionElement: HTMLElement = nodeElement;
|
const imgSelectElements = nodeElement.querySelectorAll(".img--select");
|
||||||
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
if (imgSelectElements.length > 0) {
|
||||||
if (selectElements.length > 0) {
|
const oldHTML = nodeElement.outerHTML;
|
||||||
actionElement = selectElements[0] as HTMLElement;
|
imgSelectElements.forEach((item: HTMLElement) => {
|
||||||
}
|
|
||||||
const oldHTML = actionElement.outerHTML;
|
|
||||||
actionElement.style.textAlign = "left";
|
|
||||||
actionElement.querySelectorAll(".img").forEach((item: HTMLElement) => {
|
|
||||||
item.style.display = "";
|
item.style.display = "";
|
||||||
});
|
});
|
||||||
updateTransaction(protyle, actionElement.getAttribute("data-node-id"), actionElement.outerHTML, oldHTML);
|
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
|
||||||
|
} else {
|
||||||
|
let selectElements:HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
||||||
|
if (selectElements.length === 0) {
|
||||||
|
selectElements = [nodeElement];
|
||||||
|
}
|
||||||
|
updateBatchTransaction(selectElements, protyle, (e: HTMLElement) => {
|
||||||
|
e.style.textAlign = "";
|
||||||
|
});
|
||||||
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignCenter.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignCenter.custom, event)) {
|
||||||
let actionElement: HTMLElement = nodeElement;
|
const imgSelectElements = nodeElement.querySelectorAll(".img--select");
|
||||||
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
if (imgSelectElements.length > 0) {
|
||||||
if (selectElements.length > 0) {
|
const oldHTML = nodeElement.outerHTML;
|
||||||
actionElement = selectElements[0] as HTMLElement;
|
imgSelectElements.forEach((item: HTMLElement) => {
|
||||||
}
|
|
||||||
const oldHTML = actionElement.outerHTML;
|
|
||||||
actionElement.style.textAlign = "center";
|
|
||||||
actionElement.querySelectorAll(".img").forEach((item: HTMLElement) => {
|
|
||||||
item.style.display = "block";
|
item.style.display = "block";
|
||||||
});
|
});
|
||||||
updateTransaction(protyle, actionElement.getAttribute("data-node-id"), actionElement.outerHTML, oldHTML);
|
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
|
||||||
|
} else {
|
||||||
|
let selectElements:HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
||||||
|
if (selectElements.length === 0) {
|
||||||
|
selectElements = [nodeElement];
|
||||||
|
}
|
||||||
|
updateBatchTransaction(selectElements, protyle, (e: HTMLElement) => {
|
||||||
|
e.style.textAlign = "center";
|
||||||
|
});
|
||||||
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignRight.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.alignRight.custom, event)) {
|
||||||
let actionElement: HTMLElement = nodeElement;
|
let selectElements:HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
||||||
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
if (selectElements.length === 0) {
|
||||||
if (selectElements.length > 0) {
|
selectElements = [nodeElement];
|
||||||
actionElement = selectElements[0] as HTMLElement;
|
|
||||||
}
|
}
|
||||||
const oldHTML = actionElement.outerHTML;
|
updateBatchTransaction(selectElements, protyle, (e: HTMLElement) => {
|
||||||
actionElement.style.textAlign = "right";
|
e.style.textAlign = "right";
|
||||||
updateTransaction(protyle, actionElement.getAttribute("data-node-id"), actionElement.outerHTML, oldHTML);
|
});
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -733,3 +733,24 @@ export const updateTransaction = (protyle: IProtyle, id: string, newHTML: string
|
||||||
action: "update"
|
action: "update"
|
||||||
}]);
|
}]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateBatchTransaction = (nodeElements: Element[], protyle: IProtyle, cb: (e: HTMLElement) => void) => {
|
||||||
|
const operations: IOperation[] = [];
|
||||||
|
const undoOperations: IOperation[] = [];
|
||||||
|
nodeElements.forEach((element) => {
|
||||||
|
const id = element.getAttribute("data-node-id");
|
||||||
|
element.classList.remove("protyle-wysiwyg--select");
|
||||||
|
undoOperations.push({
|
||||||
|
action: "update",
|
||||||
|
id,
|
||||||
|
data: element.outerHTML
|
||||||
|
});
|
||||||
|
cb(element as HTMLElement);
|
||||||
|
operations.push({
|
||||||
|
action: "update",
|
||||||
|
id,
|
||||||
|
data: element.outerHTML
|
||||||
|
});
|
||||||
|
});
|
||||||
|
transaction(protyle, operations, undoOperations);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue