From 666cab954a01d0fba2dafa7d50a92dc6e7d458a3 Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 21 Mar 2022 15:09:43 -0400 Subject: [PATCH] Fix emoting with emoji or pills (#8105) * Fix emoting with emoji or pills * Fix some slash command errors not being shown * Re-enable mistakenly skipped SendMessageComposer tests * Test emoting with non-text parts --- src/SlashCommands.tsx | 4 +--- src/editor/serialize.ts | 4 +++- .../views/rooms/SendMessageComposer-test.tsx | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 9bb90e607a5..b79de503523 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -153,13 +153,11 @@ export class Command { public run(roomId: string, threadId: string, args: string): RunResult { // if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me` if (!this.runFn) { - reject( + return reject( newTranslatableError( "Command error: Unable to handle slash command.", ), ); - - return; } const renderingType = threadId diff --git a/src/editor/serialize.ts b/src/editor/serialize.ts index 2c377119ad4..8e0d3d66db9 100644 --- a/src/editor/serialize.ts +++ b/src/editor/serialize.ts @@ -181,7 +181,9 @@ export function textSerialize(model: EditorModel): string { } export function containsEmote(model: EditorModel): boolean { - return startsWith(model, "/me ", false) && model.parts[0]?.text?.length > 4; + const hasCommand = startsWith(model, "/me ", false); + const hasArgument = model.parts[0]?.text?.length > 4 || model.parts.length > 1; + return hasCommand && hasArgument; } export function startsWith(model: EditorModel, prefix: string, caseSensitive = true): boolean { diff --git a/test/components/views/rooms/SendMessageComposer-test.tsx b/test/components/views/rooms/SendMessageComposer-test.tsx index 256f37947b1..2ebe162ea8e 100644 --- a/test/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/components/views/rooms/SendMessageComposer-test.tsx @@ -131,6 +131,20 @@ describe('', () => { }); }); + it("allows emoting with non-text parts", () => { + const model = new EditorModel([], createPartCreator(), createRenderer()); + const documentOffset = new DocumentOffset(16, true); + model.update("/me ✨sparkles✨", "insertText", documentOffset); + expect(model.parts.length).toEqual(4); // Emoji count as non-text + + const content = createMessageContent(model, null, undefined, permalinkCreator); + + expect(content).toEqual({ + body: "✨sparkles✨", + msgtype: "m.emote", + }); + }); + it("allows sending double-slash escaped slash commands correctly", () => { const model = new EditorModel([], createPartCreator(), createRenderer()); const documentOffset = new DocumentOffset(32, true); @@ -194,7 +208,7 @@ describe('', () => { }); }; - fit("renders text and placeholder correctly", () => { + it("renders text and placeholder correctly", () => { const wrapper = getComponent({ placeholder: "placeholder string" }); expect(wrapper.find('[aria-label="placeholder string"]')).toHaveLength(1);