Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 96c62ea

Browse files
authored
Fix avatar text issue in rte (#10559)
* replace - with zwsp * improve comments * fix broken tests * fix typo
1 parent 2978070 commit 96c62ea

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/components/views/rooms/wysiwyg_composer/utils/autocomplete.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ export function getMentionDisplayText(completion: ICompletion, client: MatrixCli
8989
*
9090
* @param completion - the item selected from the autocomplete
9191
* @param client - the MatrixClient is required for us to look up the correct room mention text
92-
* @returns an object of attributes containing HTMLAnchor attributes or data-* attri
92+
* @returns an object of attributes containing HTMLAnchor attributes or data-* attributes
9393
*/
9494
export function getMentionAttributes(completion: ICompletion, client: MatrixClient, room: Room): Attributes {
95-
// to ensure that we always have something set in the --avatar-letter CSS variable
96-
// as otherwise alignment varies depending on whether the content is empty or not
97-
const defaultLetterContent = "-";
95+
// To ensure that we always have something set in the --avatar-letter CSS variable
96+
// as otherwise alignment varies depending on whether the content is empty or not.
97+
98+
// Use a zero width space so that it counts as content, but does not display anything.
99+
const defaultLetterContent = "\u200b";
98100

99101
if (completion.type === "user") {
100102
// logic as used in UserPillPart.setAvatar in parts.ts

test/components/views/rooms/wysiwyg_composer/utils/autocomplete-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe("getMentionAttributes", () => {
173173

174174
expect(result).toEqual({
175175
"data-mention-type": "user",
176-
"style": `--avatar-background: url(${testAvatarUrlForMember}); --avatar-letter: '-'`,
176+
"style": `--avatar-background: url(${testAvatarUrlForMember}); --avatar-letter: '\u200b'`,
177177
});
178178
});
179179

@@ -200,7 +200,7 @@ describe("getMentionAttributes", () => {
200200

201201
expect(result).toEqual({
202202
"data-mention-type": "room",
203-
"style": `--avatar-background: url(${testAvatarUrlForRoom}); --avatar-letter: '-'`,
203+
"style": `--avatar-background: url(${testAvatarUrlForRoom}); --avatar-letter: '\u200b'`,
204204
});
205205
});
206206

0 commit comments

Comments
 (0)