🎨 Improve database field sorting for content containing emojis https://github.com/siyuan-note/siyuan/issues/14323

This commit is contained in:
Daniel 2025-03-11 18:16:47 +08:00
parent 020dfabcb0
commit 650493dcdb
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 15 additions and 5 deletions

View file

@ -68,7 +68,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
return 0
}
if util.PinYinCompare(value.Text.Content, other.Text.Content) {
if util.EmojiPinYinCompare(value.Text.Content, other.Text.Content) {
return -1
}
return 1
@ -243,7 +243,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
return 0
}
if util.PinYinCompare(v1, v2) {
if util.EmojiPinYinCompare(v1, v2) {
return -1
}
return 1
@ -266,7 +266,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
return 0
}
if util.PinYinCompare(value.Template.Content, other.Template.Content) {
if util.EmojiPinYinCompare(value.Template.Content, other.Template.Content) {
return -1
}
return 1
@ -314,7 +314,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
return 0
}
if util.PinYinCompare(vContent, oContent) {
if util.EmojiPinYinCompare(vContent, oContent) {
return -1
}
return 1
@ -352,7 +352,7 @@ func (value *Value) Compare(other *Value, attrView *AttributeView) int {
return 0
}
if util.PinYinCompare(vContent, oContent) {
if util.EmojiPinYinCompare(vContent, oContent) {
return -1
}
return 1

View file

@ -32,6 +32,16 @@ func NaturalCompare(str1, str2 string) bool {
return natsort.Compare(str1, str2)
}
func EmojiPinYinCompare(str1, str2 string) bool {
str1_ := strings.TrimSpace(RemoveEmojiInvisible(str1))
str2_ := strings.TrimSpace(RemoveEmojiInvisible(str2))
if str1_ == str2_ && 0 == len(str1_) {
// 全部都是 emoji 的情况按 emoji 字符串排序
return strings.Compare(str1, str2) < 0
}
return PinYinCompare(str1, str2)
}
func PinYinCompare(str1, str2 string) bool {
str1 = RemoveEmojiInvisible(str1)
str2 = RemoveEmojiInvisible(str2)