From eda9082f823c22df2f98d2f36f7a95478b40876d Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 15 Jan 2023 00:18:10 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=88=86=E7=BB=84=E6=8E=92=E5=BA=8F=20https:?= =?UTF-8?q?//github.com/siyuan-note/siyuan/issues/7071?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/workspace.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/api/workspace.go b/kernel/api/workspace.go index 6b07968c7..44c52df2e 100644 --- a/kernel/api/workspace.go +++ b/kernel/api/workspace.go @@ -21,11 +21,13 @@ import ( "net/http" "os" "path/filepath" + "sort" "strings" "time" "unicode/utf8" "github.com/88250/gulu" + "github.com/facette/natsort" "github.com/gin-gonic/gin" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/model" @@ -130,11 +132,23 @@ func getWorkspaces(c *gin.Context) { return } - var workspaces []*Workspace + var workspaces, openedWorkspaces, closedWorkspaces []*Workspace for _, p := range workspacePaths { closed := !util.IsWorkspaceLocked(p) - workspaces = append(workspaces, &Workspace{Path: p, Closed: closed}) + if closed { + closedWorkspaces = append(closedWorkspaces, &Workspace{Path: p, Closed: closed}) + } else { + openedWorkspaces = append(openedWorkspaces, &Workspace{Path: p, Closed: closed}) + } } + sort.Slice(openedWorkspaces, func(i, j int) bool { + return natsort.Compare(util.RemoveEmoji(filepath.Base(openedWorkspaces[i].Path)), util.RemoveEmoji(filepath.Base(openedWorkspaces[j].Path))) + }) + sort.Slice(closedWorkspaces, func(i, j int) bool { + return natsort.Compare(util.RemoveEmoji(filepath.Base(closedWorkspaces[i].Path)), util.RemoveEmoji(filepath.Base(closedWorkspaces[j].Path))) + }) + workspaces = append(workspaces, openedWorkspaces...) + workspaces = append(workspaces, closedWorkspaces...) ret.Data = workspaces }