🎨 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
|
@ -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'><div></code> tags to wrap and remove blank lines",
|
||||
|
|
|
@ -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'><div></code> para ajustar y eliminar líneas en blanco",
|
||||
|
|
|
@ -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'><div></code> pour envelopper et supprimer les lignes vides",
|
||||
|
|
|
@ -443,6 +443,7 @@
|
|||
"historyFormat": "格式化 (format)",
|
||||
"historySync": "同步 (sync)",
|
||||
"historyReplace": "替換 (replace)",
|
||||
"historyOutline": "大綱 (outline)",
|
||||
"htmlBlockError": "以下 script 執行會影響界面顯示,已經停止運行該腳本",
|
||||
"fileHistory": "文件歷史",
|
||||
"htmlBlockTip": "形成了多個 HTML 塊,為防止資料丟失請使用 <code class='fn__code'><div></code> 標籤包裹並去掉空行",
|
||||
|
|
|
@ -443,6 +443,7 @@
|
|||
"historyFormat": "格式化 (format)",
|
||||
"historySync": "同步 (sync)",
|
||||
"historyReplace": "替换 (replace)",
|
||||
"historyOutline": "大纲 (outline)",
|
||||
"htmlBlockError": "以下 script 执行会影响界面显示,已经停止运行该脚本",
|
||||
"fileHistory": "文件历史",
|
||||
"htmlBlockTip": "形成了多个 HTML 块,为防止数据丢失请使用 <code class='fn__code'><div></code> 标签包裹并去掉空行",
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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"}">
|
||||
|
|
|
@ -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
Reference in a new issue