♻️ Improve sorting
This commit is contained in:
parent
b6af01ecd3
commit
89f46b8148
6 changed files with 38 additions and 33 deletions
|
@ -27,7 +27,6 @@ import (
|
|||
"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"
|
||||
|
@ -252,10 +251,10 @@ func getWorkspaces(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
sort.Slice(openedWorkspaces, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(filepath.Base(openedWorkspaces[i].Path)), util.RemoveEmojiInvisible(filepath.Base(openedWorkspaces[j].Path)))
|
||||
return util.NaturalCompare(filepath.Base(openedWorkspaces[i].Path), filepath.Base(openedWorkspaces[j].Path))
|
||||
})
|
||||
sort.Slice(closedWorkspaces, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(filepath.Base(closedWorkspaces[i].Path)), util.RemoveEmojiInvisible(filepath.Base(closedWorkspaces[j].Path)))
|
||||
return util.NaturalCompare(filepath.Base(closedWorkspaces[i].Path), filepath.Base(closedWorkspaces[j].Path))
|
||||
})
|
||||
workspaces = append(workspaces, openedWorkspaces...)
|
||||
workspaces = append(workspaces, closedWorkspaces...)
|
||||
|
|
|
@ -29,7 +29,6 @@ import (
|
|||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/facette/natsort"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
@ -275,13 +274,13 @@ func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode
|
|||
case util.SortModeCreatedASC:
|
||||
return backlinks[i].Created < backlinks[j].Created
|
||||
case util.SortModeNameDESC:
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(backlinks[j].Name), util.RemoveEmojiInvisible(backlinks[i].Name))
|
||||
return util.PinYinCompare(backlinks[j].Name, backlinks[i].Name)
|
||||
case util.SortModeNameASC:
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(backlinks[i].Name), util.RemoveEmojiInvisible(backlinks[j].Name))
|
||||
return util.PinYinCompare(backlinks[i].Name, backlinks[j].Name)
|
||||
case util.SortModeAlphanumDESC:
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(backlinks[j].Name), util.RemoveEmojiInvisible(backlinks[i].Name))
|
||||
return util.NaturalCompare(backlinks[j].Name, backlinks[i].Name)
|
||||
case util.SortModeAlphanumASC:
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(backlinks[i].Name), util.RemoveEmojiInvisible(backlinks[j].Name))
|
||||
return util.NaturalCompare(backlinks[i].Name, backlinks[j].Name)
|
||||
}
|
||||
return backlinks[i].ID > backlinks[j].ID
|
||||
})
|
||||
|
@ -304,13 +303,13 @@ func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode
|
|||
case util.SortModeCreatedASC:
|
||||
return backmentions[i].Created < backmentions[j].Created
|
||||
case util.SortModeNameDESC:
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(backmentions[j].Name), util.RemoveEmojiInvisible(backmentions[i].Name))
|
||||
return util.PinYinCompare(backmentions[j].Name, backmentions[i].Name)
|
||||
case util.SortModeNameASC:
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(backmentions[i].Name), util.RemoveEmojiInvisible(backmentions[j].Name))
|
||||
return util.PinYinCompare(backmentions[i].Name, backmentions[j].Name)
|
||||
case util.SortModeAlphanumDESC:
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(backmentions[j].Name), util.RemoveEmojiInvisible(backmentions[i].Name))
|
||||
return util.NaturalCompare(backmentions[j].Name, backmentions[i].Name)
|
||||
case util.SortModeAlphanumASC:
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(backmentions[i].Name), util.RemoveEmojiInvisible(backmentions[j].Name))
|
||||
return util.NaturalCompare(backmentions[i].Name, backmentions[j].Name)
|
||||
}
|
||||
return backmentions[i].ID > backmentions[j].ID
|
||||
})
|
||||
|
@ -520,7 +519,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Bl
|
|||
}
|
||||
|
||||
var paragraphParentIDs []string
|
||||
for parentID, _ := range parentRefParagraphs {
|
||||
for parentID := range parentRefParagraphs {
|
||||
paragraphParentIDs = append(paragraphParentIDs, parentID)
|
||||
}
|
||||
sqlParagraphParents := sql.GetBlocks(paragraphParentIDs)
|
||||
|
|
|
@ -34,7 +34,6 @@ import (
|
|||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/lex"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/facette/natsort"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
|
@ -150,30 +149,30 @@ func ListNotebooks() (ret []*Box, err error) {
|
|||
switch Conf.FileTree.Sort {
|
||||
case util.SortModeNameASC:
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(ret[i].Name), util.RemoveEmojiInvisible(ret[j].Name))
|
||||
return util.PinYinCompare(ret[i].Name, ret[j].Name)
|
||||
})
|
||||
case util.SortModeNameDESC:
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(ret[j].Name), util.RemoveEmojiInvisible(ret[i].Name))
|
||||
return util.PinYinCompare(ret[j].Name, ret[i].Name)
|
||||
})
|
||||
case util.SortModeUpdatedASC:
|
||||
case util.SortModeUpdatedDESC:
|
||||
case util.SortModeAlphanumASC:
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(ret[i].Name), util.RemoveEmojiInvisible(ret[j].Name))
|
||||
return util.NaturalCompare(ret[i].Name, ret[j].Name)
|
||||
})
|
||||
case util.SortModeAlphanumDESC:
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(ret[j].Name), util.RemoveEmojiInvisible(ret[i].Name))
|
||||
return util.NaturalCompare(ret[j].Name, ret[i].Name)
|
||||
})
|
||||
case util.SortModeCustom:
|
||||
sort.Slice(ret, func(i, j int) bool { return ret[i].Sort < ret[j].Sort })
|
||||
case util.SortModeRefCountASC:
|
||||
case util.SortModeRefCountDESC:
|
||||
case util.SortModeCreatedASC:
|
||||
sort.Slice(ret, func(i, j int) bool { return natsort.Compare(ret[j].ID, ret[i].ID) })
|
||||
sort.Slice(ret, func(i, j int) bool { return util.NaturalCompare(ret[j].ID, ret[i].ID) })
|
||||
case util.SortModeCreatedDESC:
|
||||
sort.Slice(ret, func(i, j int) bool { return natsort.Compare(ret[j].ID, ret[i].ID) })
|
||||
sort.Slice(ret, func(i, j int) bool { return util.NaturalCompare(ret[j].ID, ret[i].ID) })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import (
|
|||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/parse"
|
||||
util2 "github.com/88250/lute/util"
|
||||
"github.com/facette/natsort"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
@ -388,11 +387,11 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
|
|||
switch sortMode {
|
||||
case util.SortModeNameASC:
|
||||
sort.Slice(docs, func(i, j int) bool {
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(docs[i].Name), util.RemoveEmojiInvisible(docs[j].Name))
|
||||
return util.PinYinCompare(docs[i].Name, docs[j].Name)
|
||||
})
|
||||
case util.SortModeNameDESC:
|
||||
sort.Slice(docs, func(i, j int) bool {
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(docs[j].Name), util.RemoveEmojiInvisible(docs[i].Name))
|
||||
return util.PinYinCompare(docs[j].Name, docs[i].Name)
|
||||
})
|
||||
case util.SortModeUpdatedASC:
|
||||
sort.Slice(docs, func(i, j int) bool { return docs[i].Mtime < docs[j].Mtime })
|
||||
|
@ -400,11 +399,11 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
|
|||
sort.Slice(docs, func(i, j int) bool { return docs[i].Mtime > docs[j].Mtime })
|
||||
case util.SortModeAlphanumASC:
|
||||
sort.Slice(docs, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(docs[i].Name), util.RemoveEmojiInvisible(docs[j].Name))
|
||||
return util.NaturalCompare(docs[i].Name, docs[j].Name)
|
||||
})
|
||||
case util.SortModeAlphanumDESC:
|
||||
sort.Slice(docs, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible(docs[j].Name), util.RemoveEmojiInvisible(docs[i].Name))
|
||||
return util.NaturalCompare(docs[j].Name, docs[i].Name)
|
||||
})
|
||||
case util.SortModeCustom:
|
||||
fileTreeFiles := docs
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/facette/natsort"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
@ -216,7 +215,7 @@ func BuildTags() (ret *Tags) {
|
|||
ret = &Tags{}
|
||||
labels := labelTags()
|
||||
tags := Tags{}
|
||||
for label, _ := range labels {
|
||||
for label := range labels {
|
||||
tags = buildTags(tags, strings.Split(label, "/"), 0)
|
||||
}
|
||||
appendTagChildren(&tags, labels)
|
||||
|
@ -248,19 +247,19 @@ func sortTags(tags Tags) {
|
|||
switch Conf.Tag.Sort {
|
||||
case util.SortModeNameASC:
|
||||
sort.Slice(tags, func(i, j int) bool {
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(tags[i].Name), util.RemoveEmojiInvisible(tags[j].Name))
|
||||
return util.PinYinCompare(tags[i].Name, tags[j].Name)
|
||||
})
|
||||
case util.SortModeNameDESC:
|
||||
sort.Slice(tags, func(j, i int) bool {
|
||||
return util.PinYinCompare(util.RemoveEmojiInvisible(tags[i].Name), util.RemoveEmojiInvisible(tags[j].Name))
|
||||
return util.PinYinCompare(tags[i].Name, tags[j].Name)
|
||||
})
|
||||
case util.SortModeAlphanumASC:
|
||||
sort.Slice(tags, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible((tags)[i].Name), util.RemoveEmojiInvisible((tags)[j].Name))
|
||||
return util.NaturalCompare((tags)[i].Name, (tags)[j].Name)
|
||||
})
|
||||
case util.SortModeAlphanumDESC:
|
||||
sort.Slice(tags, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible((tags)[j].Name), util.RemoveEmojiInvisible((tags)[i].Name))
|
||||
return util.NaturalCompare((tags)[j].Name, (tags)[i].Name)
|
||||
})
|
||||
case util.SortModeRefCountASC:
|
||||
sort.Slice(tags, func(i, j int) bool { return (tags)[i].Count < (tags)[j].Count })
|
||||
|
@ -268,7 +267,7 @@ func sortTags(tags Tags) {
|
|||
sort.Slice(tags, func(i, j int) bool { return (tags)[i].Count > (tags)[j].Count })
|
||||
default:
|
||||
sort.Slice(tags, func(i, j int) bool {
|
||||
return natsort.Compare(util.RemoveEmojiInvisible((tags)[i].Name), util.RemoveEmojiInvisible((tags)[j].Name))
|
||||
return util.NaturalCompare((tags)[i].Name, (tags)[j].Name)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -278,7 +277,7 @@ func SearchTags(keyword string) (ret []string) {
|
|||
defer logging.Recover() // 定位 无法添加题头图标签 https://github.com/siyuan-note/siyuan/issues/6756
|
||||
|
||||
labels := labelBlocksByKeyword(keyword)
|
||||
for label, _ := range labels {
|
||||
for label := range labels {
|
||||
_, t := search.MarkText(label, keyword, 1024, Conf.Search.CaseSensitive)
|
||||
ret = append(ret, t)
|
||||
}
|
||||
|
|
|
@ -21,11 +21,21 @@ import (
|
|||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/facette/natsort"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
func NaturalCompare(str1, str2 string) bool {
|
||||
str1 = RemoveEmojiInvisible(str1)
|
||||
str2 = RemoveEmojiInvisible(str2)
|
||||
return natsort.Compare(str1, str2)
|
||||
}
|
||||
|
||||
func PinYinCompare(str1, str2 string) bool {
|
||||
str1 = RemoveEmojiInvisible(str1)
|
||||
str2 = RemoveEmojiInvisible(str2)
|
||||
|
||||
// Doc tree, backlinks, tags and templates ignores case when sorting alphabetically by name https://github.com/siyuan-note/siyuan/issues/8360
|
||||
str1 = strings.ToLower(str1)
|
||||
str2 = strings.ToLower(str2)
|
||||
|
|
Loading…
Add table
Reference in a new issue