Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/17958

Daniel3c6cafce3190
diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts
index 7b05b95701..14f44975fe 100644
--- a/app/src/layout/dock/Files.ts
+++ b/app/src/layout/dock/Files.ts
@@ -649,6 +649,7 @@ export class Files extends Model {
const toDocOptions: {
targetNoteBook: string;
pushMode: number;
+ toTop?: boolean;
srcHeadingID?: string;
srcListItemID?: string;
targetPath?: string;
@@ -665,7 +666,10 @@ export class Files extends Model {
if (newElement.previousElementSibling) {
toDocOptions.previousPath = newElement.previousElementSibling.getAttribute("data-path");
} else {
- toDocOptions.targetPath = newElement.parentElement.previousElementSibling.getAttribute("data-path");
+ // 拖到第一个子文档上方,作为父文档的第一个子文档 https://github.com/siyuan-note/siyuan/issues/17797
+ const parentLi = newElement.parentElement.previousElementSibling as HTMLElement;
+ toDocOptions.targetPath = parentLi.getAttribute("data-path");
+ toDocOptions.toTop = true;
}
}
if (gutterTypes[0] === "nodeheading") {
diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go
index 7132597edb..e2f55e6219 100644
--- a/kernel/api/filetree.go
+++ b/kernel/api/filetree.go
@@ -242,11 +242,15 @@ func heading2Doc(c *gin.Context) {
if arg["targetPath"] != nil {
targetPath = arg["targetPath"].(string)
}
- var previousPath string
- if arg["previousPath"] != nil {
- previousPath = arg["previousPath"].(string)
- }
- srcRootBlockID, targetPath, err := model.Heading2Doc(srcHeadingID, targetNotebook, targetPath, previousPath)
+ var previousPath string
+ if arg["previousPath"] != nil {
+ previousPath = arg["previousPath"].(string)
+ }
+ var toTop bool
+ if arg["toTop"] != nil {
+ toTop = arg["toTop"].(bool)
+ }
+ srcRootBlockID, targetPath, err := model.Heading2Doc(srcHeadingID, targetNotebook, targetPath, previousPath, toTop)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
@@ -281,11 +285,15 @@ func li2Doc(c *gin.Context) {
if arg["targetPath"] != nil {
targetPath = arg["targetPath"].(string)
}
- var previousPath string
- if arg["previousPath"] != nil {
- previousPath = arg["previousPath"].(string)
- }
- srcRootBlockID, targetPath, err := model.ListItem2Doc(srcListItemID, targetNotebook, targetPath, previousPath)
+ var previousPath string
+ if arg["previousPath"] != nil {
+ previousPath = arg["previousPath"].(string)
+ }
+ var toTop bool
+ if arg["toTop"] != nil {
+ toTop = arg["toTop"].(bool)
+ }
+ srcRootBlockID, targetPath, err := model.ListItem2Doc(srcListItemID, targetNotebook, targetPath, previousPath, toTop)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
diff --git a/kernel/model/heading.go b/kernel/model/heading.go
index 83ad9d6079..3eb5ce1b52 100644
--- a/kernel/model/heading.go
+++ b/kernel/model/heading.go
@@ -302,7 +302,7 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
return
}
-func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string) (srcRootBlockID, newTargetPath string, err error) {
+func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string, toTop bool) (srcRootBlockID, newTargetPath string, err error) {
FlushTxQueue()
srcTree, _ := LoadTreeByBlockID(srcHeadingID)
@@ -425,11 +425,13 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string) (sr
newTree.Box, newTree.Path = targetBoxID, newTargetPath
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
newTree.Root.Spec = treenode.CurrentSpec
- if "" != previousPath {
- box.addSort(previousPath, newTree.ID)
- } else {
- box.setSortByConf(path.Dir(newTargetPath), newTree.ID)
- }
+ if "" != previousPath {
+ box.addSort(previousPath, newTree.ID)
+ } else if toTop {
+ box.addMinSort(path.Dir(newTargetPath), newTree.ID)
+ } else {
+ box.setSortByConf(path.Dir(newTargetPath), newTree.ID)
+ }
if err = indexWriteTreeUpsertQueue(newTree); err != nil {
return "", "", err
}
diff --git a/kernel/model/listitem.go b/kernel/model/listitem.go
index 75c190a620..a1f552f85e 100644
--- a/kernel/model/listitem.go
+++ b/kernel/model/listitem.go
@@ -27,7 +27,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
-func ListItem2Doc(srcListItemID, targetBoxID, targetPath, previousPath string) (srcRootBlockID, newTargetPath string, err error) {
+func ListItem2Doc(srcListItemID, targetBoxID, targetPath, previousPath string, toTop bool) (srcRootBlockID, newTargetPath string, err error) {
FlushTxQueue()
srcTree, _ := LoadTreeByBlockID(srcListItemID)
@@ -130,11 +130,13 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath, previousPath string) (
newTree.Box, newTree.Path = targetBoxID, newTargetPath
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
newTree.Root.Spec = treenode.CurrentSpec
- if "" != previousPath {
- box.addSort(previousPath, newTree.ID)
- } else {
- box.setSortByConf(path.Dir(newTargetPath), newTree.ID)
- }
+ if "" != previousPath {
+ box.addSort(previousPath, newTree.ID)
+ } else if toTop {
+ box.addMinSort(path.Dir(newTargetPath), newTree.ID)
+ } else {
+ box.setSortByConf(path.Dir(newTargetPath), newTree.ID)
+ }
if err = indexWriteTreeUpsertQueue(newTree); err != nil {
return "", "", err
}