From 47f884f2bbda0c46d8a32a38ba279d7916aa0744 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 20 May 2024 23:21:59 +0800 Subject: [PATCH] :bug: Some emoji exceptions in the document title https://github.com/siyuan-note/siyuan/issues/11480 --- kernel/model/file.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index 60301ef00de..e5b73b02769 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1666,7 +1666,7 @@ func RenameDoc(boxID, p, title string) (err error) { return } - title = gulu.Str.RemoveInvisible(title) + title = removeInvisibleCharsInTitle(title) if 512 < utf8.RuneCountInString(title) { // 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299 return errors.New(Conf.Language(106)) @@ -1706,7 +1706,7 @@ func RenameDoc(boxID, p, title string) (err error) { } func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) { - title = gulu.Str.RemoveInvisible(title) + title = removeInvisibleCharsInTitle(title) if 512 < utf8.RuneCountInString(title) { // 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299 err = errors.New(Conf.Language(106)) @@ -1819,6 +1819,14 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) { return } +func removeInvisibleCharsInTitle(title string) string { + // 不要踢掉 零宽连字符,否则有的 Emoji 会变形 https://github.com/siyuan-note/siyuan/issues/11480 + title = strings.ReplaceAll(title, string(gulu.ZWJ), "__@ZWJ@__") + title = gulu.Str.RemoveInvisible(title) + title = strings.ReplaceAll(title, "__@ZWJ@__", string(gulu.ZWJ)) + return title +} + func moveSorts(rootID, fromBox, toBox string) { root := treenode.GetBlockTree(rootID) if nil == root {