mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-14 00:16:13 +01:00
🎨 Generate document history when dragging outline https://github.com/siyuan-note/siyuan/issues/10834
This commit is contained in:
parent
0c4ebbeea0
commit
ac9304f589
10 changed files with 40 additions and 38 deletions
|
|
@ -17,14 +17,8 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/88250/lute/render"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -41,7 +35,7 @@ func AutoSpace(rootID string) (err error) {
|
|||
|
||||
WaitForWritingFiles()
|
||||
|
||||
generateFormatHistory(tree)
|
||||
generateOpTypeHistory(tree, HistoryOpFormat)
|
||||
luteEngine := NewLute()
|
||||
// 合并相邻的同类行级节点
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
|
|
@ -82,30 +76,3 @@ func AutoSpace(rootID string) (err error) {
|
|||
util.RandomSleep(500, 700)
|
||||
return
|
||||
}
|
||||
|
||||
func generateFormatHistory(tree *parse.Tree) {
|
||||
historyDir, err := GetHistoryDir(HistoryOpFormat)
|
||||
if nil != err {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
historyPath := filepath.Join(historyDir, tree.Box, tree.Path)
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var data []byte
|
||||
if data, err = filelock.ReadFile(filepath.Join(util.DataDir, tree.Box, tree.Path)); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.File.WriteFileSafer(historyPath, data, 0644); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -600,8 +600,36 @@ const (
|
|||
HistoryOpFormat = "format"
|
||||
HistoryOpSync = "sync"
|
||||
HistoryOpReplace = "replace"
|
||||
HistoryOpOutline = "outline"
|
||||
)
|
||||
|
||||
func generateOpTypeHistory(tree *parse.Tree, opType string) {
|
||||
historyDir, err := GetHistoryDir(opType)
|
||||
if nil != err {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
historyPath := filepath.Join(historyDir, tree.Box, tree.Path)
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var data []byte
|
||||
if data, err = filelock.ReadFile(filepath.Join(util.DataDir, tree.Box, tree.Path)); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.File.WriteFileSafer(historyPath, data, 0644); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
|
||||
}
|
||||
|
||||
func GetHistoryDir(suffix string) (ret string, err error) {
|
||||
return getHistoryDir(suffix, time.Now())
|
||||
}
|
||||
|
|
@ -641,7 +669,7 @@ func fullReindexHistory() {
|
|||
return
|
||||
}
|
||||
|
||||
var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat, HistoryOpSync, HistoryOpReplace}
|
||||
var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat, HistoryOpSync, HistoryOpReplace, HistoryOpOutline}
|
||||
|
||||
const (
|
||||
HistoryTypeDocName = 0 // Search docs by doc name
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
}
|
||||
|
||||
generateFormatHistory(tree)
|
||||
generateOpTypeHistory(tree, HistoryOpOutline)
|
||||
|
||||
targetNode := previousHeading
|
||||
previousHeadingChildren := treenode.HeadingChildren(previousHeading)
|
||||
|
|
@ -130,7 +130,7 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
}
|
||||
|
||||
generateFormatHistory(tree)
|
||||
generateOpTypeHistory(tree, HistoryOpOutline)
|
||||
|
||||
targetNode := parentHeading
|
||||
parentHeadingChildren := treenode.HeadingChildren(parentHeading)
|
||||
|
|
@ -172,7 +172,7 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
targetNode.InsertAfter(heading)
|
||||
} else {
|
||||
generateFormatHistory(tree)
|
||||
generateOpTypeHistory(tree, HistoryOpOutline)
|
||||
|
||||
// 移到最前
|
||||
for i := len(headingChildren) - 1; i >= 0; i-- {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue