Переглянути джерело

:art: 工作空间列表分组排序 https://github.com/siyuan-note/siyuan/issues/7071

Liang Ding 2 роки тому
батько
коміт
eda9082f82
1 змінених файлів з 16 додано та 2 видалено
  1. 16 2
      kernel/api/workspace.go

+ 16 - 2
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
 }