diff --git a/kernel/av/sort.go b/kernel/av/sort.go index 4002bc7e8..f8a1c8621 100644 --- a/kernel/av/sort.go +++ b/kernel/av/sort.go @@ -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 diff --git a/kernel/util/sort.go b/kernel/util/sort.go index 57c45aedc..2a6afe0f3 100644 --- a/kernel/util/sort.go +++ b/kernel/util/sort.go @@ -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)