Skip to content

Commit 0cb373f

Browse files
committed
✨(frontend) prevent duplicate emoji when used as first character in title
ensures icon and title are visually distinct in sub-document headers Signed-off-by: Cyril <[email protected]>
1 parent 5f9968d commit 0cb373f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to
1818
- ♿(frontend) improve screen reader support in DocShare modal #1628
1919
- 🐛(frontend) fix toolbar not activated when reader #1640
2020
- 🐛(frontend) preserve left panel width on window resize #1588
21+
- 🐛(frontend) prevent duplicate as first character in title #1595
2122

2223
## [3.10.0] - 2025-11-18
2324

src/frontend/apps/impress/src/features/docs/doc-header/components/DocTitle.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,17 @@ const DocTitleInput = ({ doc }: DocTitleProps) => {
122122
if (isTopRoot) {
123123
const sanitizedTitle = updateDocTitle(doc, inputText);
124124
setTitleDisplay(sanitizedTitle);
125+
return sanitizedTitle;
125126
} else {
126-
const sanitizedTitle = updateDocTitle(
127-
doc,
128-
emoji ? `${emoji} ${inputText}` : inputText,
129-
);
127+
const { emoji: pastedEmoji } = getEmojiAndTitle(inputText);
128+
const textPreservingPastedEmoji = pastedEmoji
129+
? `\u200B${inputText}`
130+
: inputText;
131+
const finalTitle = emoji
132+
? `${emoji} ${textPreservingPastedEmoji}`
133+
: textPreservingPastedEmoji;
134+
135+
const sanitizedTitle = updateDocTitle(doc, finalTitle);
130136
const { titleWithoutEmoji: sanitizedTitleWithoutEmoji } =
131137
getEmojiAndTitle(sanitizedTitle);
132138

src/frontend/apps/impress/src/features/docs/doc-management/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ export const getEmojiAndTitle = (title: string) => {
2626
// Use emoji-regex library for comprehensive emoji detection compatible with ES5
2727
const regex = emojiRegex();
2828

29-
// Check if the title starts with an emoji
30-
const match = title.match(regex);
29+
// Ignore leading spaces when checking for a leading emoji
30+
const trimmedTitle = title.trimStart();
31+
const match = trimmedTitle.match(regex);
3132

32-
if (match && title.startsWith(match[0])) {
33+
if (match && trimmedTitle.startsWith(match[0])) {
3334
const emoji = match[0];
34-
const titleWithoutEmoji = title.substring(emoji.length).trim();
35+
const titleWithoutEmoji = trimmedTitle.substring(emoji.length).trim();
3536
return { emoji, titleWithoutEmoji };
3637
}
3738

0 commit comments

Comments
 (0)