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

Commit 0e68c8c

Browse files
committed
Fix new line created when enter is pressed
1 parent c8ca47f commit 0e68c8c

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/components/views/rooms/wysiwyg_composer/hooks/useInputEventProcessor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,15 @@ function handleInputEvent(event: InputEvent, send: Send, isCtrlEnterToSend: bool
168168
case "insertParagraph":
169169
if (!isCtrlEnterToSend) {
170170
send();
171+
return null;
171172
}
172-
return null;
173+
break;
173174
case "sendMessage":
174175
if (isCtrlEnterToSend) {
175176
send();
177+
return null;
176178
}
177-
return null;
179+
break;
178180
}
179181

180182
return event;

test/components/views/rooms/wysiwyg_composer/components/WysiwygComposer-test.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,33 @@ describe("WysiwygComposer", () => {
149149

150150
it("Should not call onSend when Enter is pressed", async () => {
151151
// When
152+
const textbox = screen.getByRole("textbox");
153+
152154
fireEvent(
153-
screen.getByRole("textbox"),
155+
textbox,
154156
new InputEvent("input", {
155157
inputType: "insertParagraph",
156158
}),
157159
);
158160

159161
// Then it does not send a message
160162
await waitFor(() => expect(onSend).toBeCalledTimes(0));
163+
164+
fireEvent(
165+
textbox,
166+
new InputEvent("input", {
167+
inputType: "insertText",
168+
data: "other",
169+
}),
170+
);
171+
172+
// The focus is on the last text node
173+
await waitFor(() => {
174+
const selection = document.getSelection();
175+
if (selection) {
176+
expect(selection.focusNode.textContent).toEqual("other");
177+
}
178+
});
161179
});
162180

163181
it("Should send a message when Ctrl+Enter is pressed", async () => {

0 commit comments

Comments
 (0)