Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Unify table cell selection menus https://github.com/siyuan-note/siyuan/issues/18489

Daniel7b02cfb5a6a4
diff --git a/app/appearance/icons/index.html b/app/appearance/icons/index.html
index 3278b86dd1..534d83b581 100644
--- a/app/appearance/icons/index.html
+++ b/app/appearance/icons/index.html
@@ -1,6 +1,6 @@
<html>
<head>
-<style>
+ <style>
.fn__clear > div {
float: left;
width: 150px;
@@ -28,6 +28,18 @@
<body>
<h2>SiYuan</h2>
<div class="fn__clear">
+ <div>
+ <svg>
+ <use xlink:href="#iconTableCellsSplit"></use>
+ </svg>
+ iconTableCellsSplit
+ </div>
+ <div>
+ <svg>
+ <use xlink:href="#iconTableCellsMerge"></use>
+ </svg>
+ iconTableCellsMerge
+ </div>
<div>
<svg>
<use xlink:href="#iconScale"></use>
diff --git a/app/appearance/icons/litheness/icon.js b/app/appearance/icons/litheness/icon.js
index 700ae69e80..07cf0a9bfd 100644
--- a/app/appearance/icons/litheness/icon.js
+++ b/app/appearance/icons/litheness/icon.js
@@ -1,7 +1,13 @@
document.body.insertAdjacentHTML('afterbegin', `<svg id="iconsLitheness" style="position: absolute; width: 0; height: 0; overflow: hidden;">
<defs>
+ <symbol id="iconTableCellsSplit" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M12 15V9"/><path d="M3 15h18"/><path d="M3 9h18"/><rect width="18" height="18" x="3" y="3" rx="2"/>
+ </symbol>
+ <symbol id="iconTableCellsMerge" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M12 21v-6"/><path d="M12 9V3"/><path d="M3 15h18"/><path d="M3 9h18"/><rect width="18" height="18" x="3" y="3" rx="2"/>
+ </symbol>
<symbol id="iconScale" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
- <path d="M12 3v18"/><path d="m19 8 3 8a5 5 0 0 1-6 0zV7"/><path d="M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1"/><path d="m5 8 3 8a5 5 0 0 1-6 0zV7"/><path d="M7 21h10"/>
+ <path d="M12 3v18"/><path d="m19 8 3 8a5 5 0 0 1-6 0zV7"/><path d="M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1"/><path d="m5 8 3 8a5 5 0 0 1-6 0zV7"/><path d="M7 21h10"/>
</symbol>
<symbol id="iconDatabaseBackup" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 12a9 3 0 0 0 5 2.69"/><path d="M21 9.3V5"/><path d="M3 5v14a9 3 0 0 0 6.47 2.88"/><path d="M12 12v4h4"/><path d="M13 20a5 5 0 0 0 9-3 4.5 4.5 0 0 0-4.5-4.5c-1.33 0-2.54.54-3.41 1.41L12 16"/>
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index e03ea129fd..28ac3410f7 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -2185,6 +2185,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
if (cellElement.rowSpan > 1 || cellElement.colSpan > 1) {
otherMenus.push({
id: "cancelMerged",
+ icon: "iconTableCellsSplit",
label: window.siyuan.languages.cancelMerged,
click: () => {
const oldHTML = nodeElement.outerHTML;
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index c08628a089..b1cdf058e1 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -1,7 +1,8 @@
import {MenuItem} from "../../menus/Menu";
import {updateTransaction} from "../wysiwyg/transaction";
-import {encodeBase64, isMac} from "./compatibility";
+import {encodeBase64, isMac, readClipboard} from "./compatibility";
import {removeZWJ} from "./normalizeText";
+import {paste} from "./paste";
import {focusByRange, getEditorRange} from "./selection";
import {
buildTableGrid,
@@ -115,6 +116,42 @@ const replaceCellTag = (cell: HTMLTableCellElement, tag: "th" | "td") => {
};
const getCellText = (cell: HTMLTableCellElement) => cell.innerText.replace(/\n+$/g, "");
+
+export const getCommonTableCellStyle = (cells: HTMLTableCellElement[], property: string) => {
+ if (cells.length === 0) {
+ return undefined;
+ }
+ const value = cells[0].style.getPropertyValue(property);
+ return cells.every(cell => cell.style.getPropertyValue(property) === value) ? value : undefined;
+};
+
+export const setTableCellStyle = (protyle: IProtyle, node: HTMLElement, cells: HTMLTableCellElement[],
+ property: string, value: string) => {
+ const oldHTML = node.outerHTML;
+ cells.forEach(cell => {
+ if (value) {
+ cell.style.setProperty(property, value);
+ } else {
+ cell.style.removeProperty(property);
+ if (!cell.getAttribute("style")) {
+ cell.removeAttribute("style");
+ }
+ }
+ });
+ updateTransaction(protyle, node, oldHTML);
+};
+
+export const getTableCellBackgroundMenus = (cells: HTMLTableCellElement[], onChange: (color: string) => void) => {
+ const backgroundColor = getCommonTableCellStyle(cells, "background-color");
+ const colors = ["", ...Array.from({length: 13}, (_, index) => `var(--b3-font-background${index + 1})`)];
+ return colors.map((color, index) => ({
+ label: index === 0 ? window.siyuan.languages.default : `${window.siyuan.languages.colorPrimary} ${index}`,
+ iconHTML: `<span class="protyle-table-control__color" style="${color ? `background-color: ${color}` : ""}"></span>`,
+ checked: backgroundColor === color,
+ click: () => onChange(color),
+ }));
+};
+
const TABLE_HANDLE_THICKNESS = 16;
const TABLE_ADD_CONTROL_THICKNESS = 16;
const TABLE_EDGE_CONTROL_TRIGGER_SIZE = 8;
@@ -962,8 +999,20 @@ export class TableControl {
this.selection.mode !== "cell" && merged ? window.siyuan.languages.cancelMerged : undefined,
click: () => this.execClipboardCommand("cut"),
}).element);
- menu.append(new MenuItem({type: "separator"}).element);
+ if (!this.protyle.disabled && this.selection.mode === "cell") {
+ menu.append(new MenuItem({
+ icon: "iconPaste",
+ label: window.siyuan.languages.paste,
+ click: () => this.paste(),
+ }).element);
+ menu.append(new MenuItem({
+ icon: "iconTrashcan",
+ label: window.siyuan.languages.clear,
+ click: () => this.clearCells(),
+ }).element);
+ }
if (!this.protyle.disabled) {
+ menu.append(new MenuItem({type: "separator"}).element);
this.appendInsertMenus();
if (this.selection.mode !== "cell") {
menu.append(new MenuItem({
@@ -1154,6 +1203,27 @@ export class TableControl {
document.execCommand(command);
}
+ private async paste() {
+ if (!this.selection?.activeCell.isConnected) {
+ return;
+ }
+ const cell = this.selection.activeCell;
+ const range = getEditorRange(cell);
+ range.selectNodeContents(cell);
+ range.collapse(true);
+ focusByRange(range);
+ if (document.queryCommandSupported("paste")) {
+ document.execCommand("paste");
+ } else {
+ try {
+ const text = await readClipboard();
+ paste(this.protyle, Object.assign(text, {target: cell}));
+ } catch (error) {
+ console.log(error);
+ }
+ }
+ }
+
private appendCellMenus(rectangle: boolean) {
this.appendAlignmentMenus();
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
@@ -1179,24 +1249,11 @@ export class TableControl {
click: () => this.setCellStyle("vertical-align", ""),
}).element);
const cells = this.getSelectedCells();
- const mergedCell = cells.length === 1 && (cells[0].rowSpan > 1 || cells[0].colSpan > 1);
- if (mergedCell || cells.length > 1) {
- window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
- window.siyuan.menus.menu.append(new MenuItem({
- label: mergedCell ? window.siyuan.languages.cancelMerged : window.siyuan.languages.mergeCell,
- disabled: !mergedCell && (!rectangle || !this.isSelectionInOneSection()),
- accelerator: !mergedCell && !rectangle ? window.siyuan.languages.tableRectangleSelectionRequired : undefined,
- click: () => mergedCell ? this.splitCell(cells[0]) : this.mergeCells(),
- }).element);
- }
const rowSelection = getTableFullRowSelection(this.selection.table, cells);
const columnSelection = getTableFullColumnSelection(this.selection.table, cells);
- window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
- window.siyuan.menus.menu.append(new MenuItem({
- icon: "iconClear",
- label: window.siyuan.languages.clear,
- click: () => this.clearCells(),
- }).element);
+ if (rowSelection.indexes.length > 0 || columnSelection.indexes.length > 0) {
+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ }
if (rowSelection.indexes.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconTrashcan",
@@ -1223,6 +1280,17 @@ export class TableControl {
},
}).element);
}
+ const mergedCell = cells.length === 1 && (cells[0].rowSpan > 1 || cells[0].colSpan > 1);
+ if (mergedCell || cells.length > 1) {
+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ icon: mergedCell ? "iconTableCellsSplit" : "iconTableCellsMerge",
+ label: mergedCell ? window.siyuan.languages.cancelMerged : window.siyuan.languages.mergeCell,
+ disabled: !mergedCell && (!rectangle || !this.isSelectionInOneSection()),
+ accelerator: !mergedCell && !rectangle ? window.siyuan.languages.tableRectangleSelectionRequired : undefined,
+ click: () => mergedCell ? this.splitCell(cells[0]) : this.mergeCells(),
+ }).element);
+ }
}
private appendAlignmentMenus() {
@@ -1254,12 +1322,7 @@ export class TableControl {
}
private getCommonCellStyle(property: string) {
- const cells = this.getSelectedCells();
- if (cells.length === 0) {
- return undefined;
- }
- const value = cells[0].style.getPropertyValue(property);
- return cells.every(cell => cell.style.getPropertyValue(property) === value) ? value : undefined;
+ return getCommonTableCellStyle(this.getSelectedCells(), property);
}
private isSelectionInOneSection() {
@@ -1268,32 +1331,14 @@ export class TableControl {
}
private getBackgroundMenus(): IMenu[] {
- const backgroundColor = this.getCommonCellStyle("background-color");
- const colors = ["", ...Array.from({length: 13}, (_, index) => `var(--b3-font-background${index + 1})`)];
- return colors.map((color, index) => ({
- label: index === 0 ? window.siyuan.languages.default : `${window.siyuan.languages.colorPrimary} ${index}`,
- iconHTML: `<span class="protyle-table-control__color" style="${color ? `background-color: ${color}` : ""}"></span>`,
- checked: backgroundColor === color,
- click: () => this.setCellStyle("background-color", color),
- }));
+ return getTableCellBackgroundMenus(this.getSelectedCells(), color => this.setCellStyle("background-color", color));
}
private setCellStyle(property: string, value: string) {
if (!this.selection) {
return;
}
- const oldHTML = this.selection.node.outerHTML;
- this.getSelectedCells().forEach(cell => {
- if (value) {
- cell.style.setProperty(property, value);
- } else {
- cell.style.removeProperty(property);
- if (!cell.getAttribute("style")) {
- cell.removeAttribute("style");
- }
- }
- });
- updateTransaction(this.protyle, this.selection.node, oldHTML);
+ setTableCellStyle(this.protyle, this.selection.node, this.getSelectedCells(), property, value);
this.scheduleRender();
}
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 61cc7a35e8..4dbfa9d442 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -102,10 +102,14 @@ import {
getTableFullRowSelection,
getTableRangeHTML,
isIncludeCell,
- setTableAlign,
updateTableTitle,
} from "../util/table";
-import {TableControl} from "../util/tableControl";
+import {
+ getCommonTableCellStyle,
+ getTableCellBackgroundMenus,
+ setTableCellStyle,
+ TableControl,
+} from "../util/tableControl";
import {countBlockWord, countSelectWord} from "../../layout/status";
import {showMessage} from "../../dialog/message";
import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
@@ -2279,9 +2283,30 @@ export class WYSIWYG {
getSelection().getRangeAt(0).collapse(false);
}
window.siyuan.menus.menu.remove();
+ const tableElement = tableBlockElement.querySelector("table");
+ const selectedCellElements: HTMLTableCellElement[] = [];
+ const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
+ const scrollTop = tableElement.scrollTop;
+ tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
+ if (!item.classList.contains("fn__none") && isIncludeCell({
+ tableSelectElement,
+ scrollLeft,
+ scrollTop,
+ item,
+ })) {
+ selectedCellElements.push(item);
+ }
+ });
+ const setSelectedCellStyle = (property: string, value: string) => {
+ tableSelectElement.removeAttribute("style");
+ setTableCellStyle(protyle, tableBlockElement as HTMLElement, selectedCellElements,
+ property, value);
+ };
+ let mergeCellMenuElement: HTMLElement;
if (!protyle.disabled) {
- window.siyuan.menus.menu.append(new MenuItem({
+ mergeCellMenuElement = new MenuItem({
id: "mergeCell",
+ icon: "iconTableCellsMerge",
label: window.siyuan.languages.mergeCell,
click: () => {
if (tableBlockElement) {
@@ -2407,118 +2432,20 @@ export class WYSIWYG {
});
}
}
- }).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "separator_1",
- type: "separator"
- }).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "alignLeft",
- icon: "iconAlignLeft",
- accelerator: window.siyuan.config.keymap.editor.general.alignLeft.custom,
- label: window.siyuan.languages.alignLeft,
- click: () => {
- if (tableBlockElement) {
- const selectCellElements: HTMLTableCellElement[] = [];
- const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
- const scrollTop = tableBlockElement.querySelector("table").scrollTop;
- tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
- if (!item.classList.contains("fn__none") &&
- isIncludeCell({
- tableSelectElement,
- scrollLeft,
- scrollTop,
- item,
- }) && (selectCellElements.length === 0 || (selectCellElements.length > 0 && item.offsetTop === selectCellElements[0].offsetTop))) {
- selectCellElements.push(item);
- }
- });
- tableSelectElement.removeAttribute("style");
- setTableAlign(protyle, selectCellElements, tableBlockElement, "left", getEditorRange(tableBlockElement));
- }
- }
- }).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "alignCenter",
- icon: "iconAlignCenter",
- accelerator: window.siyuan.config.keymap.editor.general.alignCenter.custom,
- label: window.siyuan.languages.alignCenter,
- click: () => {
- if (tableBlockElement) {
- const selectCellElements: HTMLTableCellElement[] = [];
- const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
- const scrollTop = tableBlockElement.querySelector("table").scrollTop;
- tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
- if (!item.classList.contains("fn__none") && isIncludeCell({
- tableSelectElement,
- scrollLeft,
- scrollTop,
- item,
- }) &&
- (selectCellElements.length === 0 || (selectCellElements.length > 0 && item.offsetTop === selectCellElements[0].offsetTop))) {
- selectCellElements.push(item);
- }
- });
- tableSelectElement.removeAttribute("style");
- setTableAlign(protyle, selectCellElements, tableBlockElement, "center", getEditorRange(tableBlockElement));
- }
- }
- }).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "alignRight",
- icon: "iconAlignRight",
- accelerator: window.siyuan.config.keymap.editor.general.alignRight.custom,
- label: window.siyuan.languages.alignRight,
- click: () => {
- if (tableBlockElement) {
- const selectCellElements: HTMLTableCellElement[] = [];
- const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
- const scrollTop = tableBlockElement.querySelector("table").scrollTop;
- tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
- if (!item.classList.contains("fn__none") && isIncludeCell({
- tableSelectElement,
- scrollLeft,
- scrollTop,
- item,
- }) && (selectCellElements.length === 0 || (selectCellElements.length > 0 && item.offsetTop === selectCellElements[0].offsetTop))) {
- selectCellElements.push(item);
- }
- });
- tableSelectElement.removeAttribute("style");
- setTableAlign(protyle, selectCellElements, tableBlockElement, "right", getEditorRange(tableBlockElement));
- }
- }
- }).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "useDefaultAlign",
- icon: "",
- label: window.siyuan.languages.useDefaultAlign,
- click: () => {
- if (tableBlockElement) {
- const selectCellElements: HTMLTableCellElement[] = [];
- const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
- const scrollTop = tableBlockElement.querySelector("table").scrollTop;
- tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
- if (!item.classList.contains("fn__none") && isIncludeCell({
- tableSelectElement,
- scrollLeft,
- scrollTop,
- item,
- }) &&
- (selectCellElements.length === 0 || (selectCellElements.length > 0 && item.offsetTop === selectCellElements[0].offsetTop))) {
- selectCellElements.push(item);
- }
- });
- tableSelectElement.removeAttribute("style");
- setTableAlign(protyle, selectCellElements, tableBlockElement, "", getEditorRange(tableBlockElement));
- }
- }
- }).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "separator_2",
- type: "separator"
- }).element);
+ }).element;
}
+ window.siyuan.menus.menu.append(new MenuItem({
+ id: "copy",
+ icon: "iconCopy",
+ accelerator: "⌘C",
+ label: window.siyuan.languages.copy,
+ click() {
+ if (tableBlockElement) {
+ focusByRange(getEditorRange(tableBlockElement));
+ document.execCommand("copy");
+ }
+ }
+ }).element);
/// #if !MOBILE
window.siyuan.menus.menu.append(new MenuItem({
id: "copyRichText",
@@ -2537,25 +2464,11 @@ export class WYSIWYG {
label: window.siyuan.languages.copyPlainText,
click() {
if (tableBlockElement) {
- const selectCellElements: HTMLTableCellElement[] = [];
- const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
- const scrollTop = tableBlockElement.querySelector("table").scrollTop;
- const tableSelectElement = tableBlockElement.querySelector(".table__select") as HTMLElement;
- tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
- if (!item.classList.contains("fn__none") && isIncludeCell({
- tableSelectElement,
- scrollLeft,
- scrollTop,
- item,
- })) {
- selectCellElements.push(item);
- }
- });
let textPlain = "";
- selectCellElements.forEach((item, index) => {
+ selectedCellElements.forEach((item, index) => {
textPlain += item.textContent.trim() + "\t";
- if (!item.nextElementSibling || !selectCellElements[index + 1] ||
- item.nextElementSibling !== selectCellElements[index + 1]) {
+ if (!item.nextElementSibling || !selectedCellElements[index + 1] ||
+ item.nextElementSibling !== selectedCellElements[index + 1]) {
textPlain = textPlain.slice(0, -1) + "\n";
}
});
@@ -2564,18 +2477,6 @@ export class WYSIWYG {
}
}
}).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "copy",
- icon: "iconCopy",
- accelerator: "⌘C",
- label: window.siyuan.languages.copy,
- click() {
- if (tableBlockElement) {
- focusByRange(getEditorRange(tableBlockElement));
- document.execCommand("copy");
- }
- }
- }).element);
if (!protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({
id: "cut",
@@ -2595,9 +2496,13 @@ export class WYSIWYG {
icon: "iconPaste",
accelerator: "⌘V",
async click() {
+ if (!tableBlockElement) {
+ return;
+ }
+ focusByRange(getEditorRange(tableBlockElement));
if (document.queryCommandSupported("paste")) {
document.execCommand("paste");
- } else if (tableBlockElement) {
+ } else {
try {
const text = await readClipboard();
paste(protyle, Object.assign(text, {target: tableBlockElement as HTMLElement}));
@@ -2607,10 +2512,6 @@ export class WYSIWYG {
}
}
}).element);
- window.siyuan.menus.menu.append(new MenuItem({
- id: "deleteRowsSeparator",
- type: "separator",
- }).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "clear",
label: window.siyuan.languages.clear,
@@ -2620,22 +2521,72 @@ export class WYSIWYG {
clearTableCell(protyle, tableBlockElement as HTMLElement);
}
}).element);
- const tableElement = tableBlockElement.querySelector("table");
- const selectedCellElements: HTMLTableCellElement[] = [];
- const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
- const scrollTop = tableElement.scrollTop;
- tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
- if (!item.classList.contains("fn__none") && isIncludeCell({
- tableSelectElement,
- scrollLeft,
- scrollTop,
- item,
- })) {
- selectedCellElements.push(item);
- }
- });
+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ icon: "iconTheme",
+ label: window.siyuan.languages.colorPrimary,
+ submenu: getTableCellBackgroundMenus(selectedCellElements,
+ color => setSelectedCellStyle("background-color", color)),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ const textAlign = getCommonTableCellStyle(selectedCellElements, "text-align");
+ window.siyuan.menus.menu.append(new MenuItem({
+ id: "alignLeft",
+ icon: "iconAlignLeft",
+ accelerator: window.siyuan.config.keymap.editor.general.alignLeft.custom,
+ label: window.siyuan.languages.alignLeft,
+ checked: textAlign === "left",
+ click: () => setSelectedCellStyle("text-align", "left"),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ id: "alignCenter",
+ icon: "iconAlignCenter",
+ accelerator: window.siyuan.config.keymap.editor.general.alignCenter.custom,
+ label: window.siyuan.languages.alignCenter,
+ checked: textAlign === "center",
+ click: () => setSelectedCellStyle("text-align", "center"),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ id: "alignRight",
+ icon: "iconAlignRight",
+ accelerator: window.siyuan.config.keymap.editor.general.alignRight.custom,
+ label: window.siyuan.languages.alignRight,
+ checked: textAlign === "right",
+ click: () => setSelectedCellStyle("text-align", "right"),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ id: "useDefaultHorizontalAlign",
+ label: window.siyuan.languages.useDefaultHorizontalAlign,
+ checked: textAlign === "",
+ click: () => setSelectedCellStyle("text-align", ""),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ const verticalAlign = getCommonTableCellStyle(selectedCellElements, "vertical-align");
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.alignTop,
+ checked: verticalAlign === "top",
+ click: () => setSelectedCellStyle("vertical-align", "top"),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.alignMiddle,
+ checked: verticalAlign === "middle",
+ click: () => setSelectedCellStyle("vertical-align", "middle"),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.alignBottom,
+ checked: verticalAlign === "bottom",
+ click: () => setSelectedCellStyle("vertical-align", "bottom"),
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.useDefaultVerticalAlign,
+ checked: verticalAlign === "",
+ click: () => setSelectedCellStyle("vertical-align", ""),
+ }).element);
const rowSelection = getTableFullRowSelection(tableElement, selectedCellElements);
const columnSelection = getTableFullColumnSelection(tableElement, selectedCellElements);
+ if (rowSelection.indexes.length > 0 || columnSelection.indexes.length > 0) {
+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ }
if (rowSelection.indexes.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({
id: "deleteRows",
@@ -2665,6 +2616,8 @@ export class WYSIWYG {
},
}).element);
}
+ window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ window.siyuan.menus.menu.append(mergeCellMenuElement);
}
window.siyuan.menus.menu.popup({x: mouseUpEvent.clientX - 8, y: mouseUpEvent.clientY - 16});
}