Skip to content

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

:bug: Fix merged rich cell rendering, undo and focus outlines https://github.com/siyuan-note/siyuan/issues/19188

Daniel4e92867ad074
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index 56899c8fca..a907f5075a 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -898,6 +898,11 @@
}
.protyle-wysiwyg [data-type="NodeTable"] {
+ td[tabindex="-1"]:focus,
+ th[tabindex="-1"]:focus {
+ outline: none;
+ }
+
td:empty::after,
th:empty::after {
// 空单元格与输入文字共用行盒高度,避免输入第一个字符时改变整行高度。
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index e13b75edce..dbc7b74563 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -1,10 +1,12 @@
import {MenuItem} from "../../menus/Menu";
import {clearTableCellContent, getTableCellRichPlainText, mergeTableCellContents} from "./tableCellRich";
+import {renderTableCellRichElements} from "../render/tableCellRich";
import {updateTransaction} from "../wysiwyg/transaction";
import {copyPlainText, encodeBase64, isMac, readClipboard} from "./compatibility";
import {removeZWJ} from "./normalizeText";
import {paste} from "./paste";
import {focusByRange, getEditorRange} from "./selection";
+import {matchHotKey} from "./hotKey";
import {
buildTableGrid,
deleteTableColumns,
@@ -526,6 +528,26 @@ export class TableControl {
if (!this.selection || this.protyle.disabled) {
return;
}
+ const keymap = window.siyuan.config.keymap.editor.general;
+ const undo = matchHotKey(keymap.undo, event);
+ const redo = matchHotKey(keymap.redo, event);
+ if (!event.isComposing && (undo || redo)) {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ // 单元格选择不持有文字选区,撤销前将焦点交回所属编辑器。
+ const range = document.createRange();
+ range.selectNodeContents(this.selection.activeCell);
+ range.collapse(true);
+ this.wysiwygElement.focus({preventScroll: true});
+ focusByRange(range);
+ this.clear();
+ if (undo) {
+ this.protyle.undo.undo(this.protyle);
+ } else {
+ this.protyle.undo.redo(this.protyle);
+ }
+ return;
+ }
if (!event.isComposing && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey &&
(event.key === "Backspace" || event.key === "Delete")) {
event.preventDefault();
@@ -2018,6 +2040,7 @@ export class TableControl {
first.rowSpan = rowEnd - rowStart + 1;
first.colSpan = colEnd - colStart + 1;
updateTransaction(this.protyle, this.selection.node, oldHTML);
+ renderTableCellRichElements(first);
this.selection.cells = new Set([first]);
this.selection.activeCell = first;
this.hoverCell = first;