🎨 Generate document history when dragging outline https://github.com/siyuan-note/siyuan/issues/10834

This commit is contained in:
Daniel 2024-04-02 17:35:01 +08:00
parent 0c4ebbeea0
commit ac9304f589
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
10 changed files with 40 additions and 38 deletions

View file

@ -443,6 +443,7 @@
"historyFormat": "format",
"historySync": "sync",
"historyReplace": "replace",
"historyOutline": "outline",
"htmlBlockError": "The execution of the following script will affect the interface display, and the script has stopped running",
"fileHistory": "File history",
"htmlBlockTip": "Multiple HTML blocks are formed. To prevent data loss, please use <code class='fn__code'>&lt;div&gt;</code> tags to wrap and remove blank lines",

View file

@ -443,6 +443,7 @@
"historyFormat": "formatear (format)",
"historySync": "sincronizar (sync)",
"historyReplace": "reemplazar (replace)",
"historyOutline": "esquema (outline)",
"htmlBlockError": "La ejecución del siguiente script afectará la visualización de la interfaz y el script ha dejado de ejecutarse",
"fileHistory": "Historial de archivos",
"htmlBlockTip": "Se forman varios bloques HTML. Para evitar la pérdida de datos, utilice etiquetas <code class='fn__code'>&lt;div&gt;</code> para ajustar y eliminar líneas en blanco",

View file

@ -443,6 +443,7 @@
"historyFormat": "formater (format)",
"historySync": "synchroniser (sync)",
"historyReplace": "remplacer (replace)",
"historyOutline": "contour (outline)",
"htmlBlockError": "L'exécution du script suivant affectera l'affichage de l'interface et le script a cessé de s'exécuter",
"fileHistory": "Historique des fichiers",
"htmlBlockTip": "Plusieurs blocs HTML sont formés. Pour éviter la perte de données, veuillez utiliser les balises <code class='fn__code'>&lt;div&gt;</code> pour envelopper et supprimer les lignes vides",

View file

@ -443,6 +443,7 @@
"historyFormat": "格式化 (format)",
"historySync": "同步  (sync)",
"historyReplace": "替換  (replace)",
"historyOutline": "大綱  (outline)",
"htmlBlockError": "以下 script 執行會影響界面顯示,已經停止運行該腳本",
"fileHistory": "文件歷史",
"htmlBlockTip": "形成了多個 HTML 塊,為防止資料丟失請使用 <code class='fn__code'>&lt;div&gt;</code> 標籤包裹並去掉空行",

View file

@ -443,6 +443,7 @@
"historyFormat": "格式化 (format)",
"historySync": "同步  (sync)",
"historyReplace": "替换  (replace)",
"historyOutline": "大纲  (outline)",
"htmlBlockError": "以下 script 执行会影响界面显示,已经停止运行该脚本",
"fileHistory": "文件历史",
"htmlBlockTip": "形成了多个 HTML 块,为防止数据丢失请使用 <code class='fn__code'>&lt;div&gt;</code> 标签包裹并去掉空行",

View file

@ -73,6 +73,7 @@ export const openDocHistory = (options: {
<option value="format">${window.siyuan.languages.historyFormat}</option>
<option value="sync">${window.siyuan.languages.historySync}</option>
<option value="replace">${window.siyuan.languages.historyReplace}</option>
<option value="outline">${window.siyuan.languages.historyOutline}</option>
</select>
<span class="fn__space"></span>
<span data-type="docprevious" class="block__icon block__icon--show b3-tooltips b3-tooltips__s" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href="#iconLeft"></use></svg></span>

View file

@ -355,6 +355,7 @@ export const openHistory = (app: App) => {
<option value="format">${window.siyuan.languages.historyFormat}</option>
<option value="sync">${window.siyuan.languages.historySync}</option>
<option value="replace">${window.siyuan.languages.historyReplace}</option>
<option value="outline">${window.siyuan.languages.historyOutline}</option>
</select>
<span class="fn__space"></span>
<select data-type="notebookselect" class="b3-select ${isMobile() ? "fn__size96" : "fn__size200"}">

View file

@ -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())
}

View file

@ -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

View file

@ -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-- {