🎨 Sort tx queue Undo and then redo after Shift+Enter trigger status exception https://github.com/siyuan-note/siyuan/issues/9178

This commit is contained in:
Daniel 2023-09-14 00:51:20 +08:00
parent 6ffa2425d2
commit f77f82258e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 9 additions and 0 deletions

View file

@ -53,12 +53,16 @@ func performTransactions(c *gin.Context) {
return
}
timestamp := int64(arg["reqId"].(float64))
var transactions []*model.Transaction
if err = gulu.JSON.UnmarshalJSON(data, &transactions); nil != err {
ret.Code = -1
ret.Msg = "parses request failed"
return
}
for _, transaction := range transactions {
transaction.Timestamp = timestamp
}
model.PerformTransactions(&transactions)

View file

@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"path/filepath"
"sort"
"strings"
"sync"
"time"
@ -152,6 +153,9 @@ func mergeTx() (ret *Transaction) {
func PerformTransactions(transactions *[]*Transaction) {
txQueueLock.Lock()
txQueue = append(txQueue, *transactions...)
sort.Slice(txQueue, func(i, j int) bool {
return txQueue[i].Timestamp < txQueue[j].Timestamp
})
txQueueLock.Unlock()
return
}
@ -1101,6 +1105,7 @@ type Operation struct {
}
type Transaction struct {
Timestamp int64 `json:"timestamp"`
DoOperations []*Operation `json:"doOperations"`
UndoOperations []*Operation `json:"undoOperations"`