mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-07 09:18:49 +01:00
🐛 Improve outline dnd https://github.com/siyuan-note/siyuan/issues/10828
This commit is contained in:
parent
26764ff9f6
commit
20ee605bfc
1 changed files with 25 additions and 5 deletions
|
|
@ -173,12 +173,32 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
|||
} else {
|
||||
generateOpTypeHistory(tree, HistoryOpOutline)
|
||||
|
||||
// 移到最前
|
||||
for i := len(headingChildren) - 1; i >= 0; i-- {
|
||||
child := headingChildren[i]
|
||||
tree.Root.PrependChild(child)
|
||||
// 移到第一个标题前
|
||||
var firstHeading *ast.Node
|
||||
for n := tree.Root.FirstChild; nil != n; n = n.Next {
|
||||
if ast.NodeHeading == n.Type {
|
||||
firstHeading = n
|
||||
break
|
||||
}
|
||||
}
|
||||
if nil == firstHeading || firstHeading.ID == heading.ID {
|
||||
return
|
||||
}
|
||||
|
||||
diffLevel := heading.HeadingLevel - firstHeading.HeadingLevel
|
||||
heading.HeadingLevel = firstHeading.HeadingLevel
|
||||
|
||||
firstHeading.InsertBefore(heading)
|
||||
for i := 0; i < len(headingChildren)-1; i++ {
|
||||
child := headingChildren[i]
|
||||
if ast.NodeHeading == child.Type {
|
||||
child.HeadingLevel -= diffLevel
|
||||
if 6 < child.HeadingLevel {
|
||||
child.HeadingLevel = 6
|
||||
}
|
||||
}
|
||||
firstHeading.InsertBefore(child)
|
||||
}
|
||||
tree.Root.PrependChild(heading)
|
||||
}
|
||||
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue