Skip to content

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

:bug: Fix undo after merging table cells https://github.com/siyuan-note/siyuan/issues/18278

Daniel00d806f06f05
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 088a799c89..c9e47c3910 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -116,6 +116,7 @@ export class WYSIWYG {
public preventKeyup: boolean;
private preventClick: boolean;
+ private preventInput: boolean;
constructor(protyle: IProtyle) {
this.element = document.createElement("div");
@@ -1777,7 +1778,12 @@ export class WYSIWYG {
selectCellElements[0].colSpan = colSpan;
selectCellElements[0].rowSpan = rowSpan;
focusByWbr(selectCellElements[0], document.createRange());
- document.execCommand("insertHTML", false, "");
+ this.preventInput = true;
+ try {
+ document.execCommand("insertHTML", false, "");
+ } finally {
+ this.preventInput = false;
+ }
updateTransaction(protyle, tableBlockElement, oldHTML);
}
});
@@ -2830,6 +2836,10 @@ export class WYSIWYG {
let timeout: number;
this.element.addEventListener("input", (event: InputEvent) => {
+ if (this.preventInput) {
+ event.stopPropagation();
+ return;
+ }
const target = event.target as HTMLElement;
if (target.tagName === "VIDEO" || target.tagName === "AUDIO" || event.inputType === "historyRedo") {
return;
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 36cd67c88d..6505cb3075 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -207,10 +207,10 @@ func performTx(tx *Transaction) (ret *TxErr) {
if e := recover(); nil != e {
msg := fmt.Sprintf("PANIC RECOVERED: %v\n\t%s\n", e, logging.ShortStack())
logging.LogError(msg)
+ ret = &TxErr{code: TxErrCodePushMsg, msg: fmt.Sprintf("transaction panic: %v", e)}
if 1 == tx.state.Load() {
tx.rollback()
- return
}
}
}()
@@ -1501,13 +1501,19 @@ func (tx *Transaction) processGlobalAssets(tree *parse.Tree) {
func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
id := operation.ID
+ updateData, ok := operation.Data.(string)
+ if !ok || "" == updateData {
+ logging.LogErrorf("update data is nil")
+ return &TxErr{code: TxErrCodeBlockNotFound, id: id}
+ }
+
tree, err := tx.loadTree(id)
if err != nil {
logging.LogErrorf("load tree [%s] failed: %s", id, err)
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
}
- data := strings.ReplaceAll(operation.Data.(string), editor.FrontEndCaret, "")
+ data := strings.ReplaceAll(updateData, editor.FrontEndCaret, "")
if "" == data {
logging.LogErrorf("update data is nil")
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
diff --git a/kernel/model/transaction_test.go b/kernel/model/transaction_test.go
new file mode 100644
index 0000000000..26beb10057
--- /dev/null
+++ b/kernel/model/transaction_test.go
@@ -0,0 +1,30 @@
+// SiYuan - Refactor your thinking
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package model
+
+import "testing"
+
+func TestDoUpdateRejectsInvalidData(t *testing.T) {
+ tests := []any{nil, 1, ""}
+ for _, data := range tests {
+ tx := &Transaction{}
+ err := tx.doUpdate(&Operation{ID: "20260718000000-abcdefg", Data: data})
+ if nil == err {
+ t.Fatalf("expected invalid update data [%v] to be rejected", data)
+ }
+ }
+}