From 837115ece3eef8b457ad5fb8abc8bf4fe7e17f47 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Wed, 11 Jan 2023 18:56:01 +0100 Subject: [PATCH] Fix unexpected composer growing (#9889) * Stop the enter event propagation when a message is sent to avoid the composer to grow. * Update @matrix-org/matrix-wysiwyg to 0.16.0 --- package.json | 2 +- .../hooks/useInputEventProcessor.ts | 14 +++++++++++--- yarn.lock | 8 ++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index cf00952f23..5fa2970973 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "dependencies": { "@babel/runtime": "^7.12.5", "@matrix-org/analytics-events": "^0.3.0", - "@matrix-org/matrix-wysiwyg": "^0.14.0", + "@matrix-org/matrix-wysiwyg": "^0.16.0", "@matrix-org/react-sdk-module-api": "^0.0.3", "@sentry/browser": "^7.0.0", "@sentry/tracing": "^7.0.0", diff --git a/src/components/views/rooms/wysiwyg_composer/hooks/useInputEventProcessor.ts b/src/components/views/rooms/wysiwyg_composer/hooks/useInputEventProcessor.ts index d84c6420b7..a94a8db9e9 100644 --- a/src/components/views/rooms/wysiwyg_composer/hooks/useInputEventProcessor.ts +++ b/src/components/views/rooms/wysiwyg_composer/hooks/useInputEventProcessor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { WysiwygInputEvent } from "@matrix-org/matrix-wysiwyg"; +import { WysiwygEvent } from "@matrix-org/matrix-wysiwyg"; import { useCallback } from "react"; import { useSettingValue } from "../../../../../hooks/useSettings"; @@ -22,12 +22,20 @@ import { useSettingValue } from "../../../../../hooks/useSettings"; export function useInputEventProcessor(onSend: () => void) { const isCtrlEnter = useSettingValue("MessageComposerInput.ctrlEnterToSend"); return useCallback( - (event: WysiwygInputEvent) => { + (event: WysiwygEvent) => { if (event instanceof ClipboardEvent) { return event; } - if ((event.inputType === "insertParagraph" && !isCtrlEnter) || event.inputType === "sendMessage") { + const isKeyboardEvent = event instanceof KeyboardEvent; + const isEnterPress = + !isCtrlEnter && (isKeyboardEvent ? event.key === "Enter" : event.inputType === "insertParagraph"); + // sendMessage is sent when ctrl+enter is pressed + const isSendMessage = !isKeyboardEvent && event.inputType === "sendMessage"; + + if (isEnterPress || isSendMessage) { + event.stopPropagation?.(); + event.preventDefault?.(); onSend(); return null; } diff --git a/yarn.lock b/yarn.lock index 28c15fa27f..aba8ea03eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1589,10 +1589,10 @@ resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-js/-/matrix-sdk-crypto-js-0.1.0-alpha.2.tgz#a09d0fea858e817da971a3c9f904632ef7b49eb6" integrity sha512-oVkBCh9YP7H9i4gAoQbZzswniczfo/aIptNa4dxRi4Ff9lSvUCFv6Hvzi7C+90c0/PWZLXjIDTIAWZYmwyd2fA== -"@matrix-org/matrix-wysiwyg@^0.14.0": - version "0.14.0" - resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-0.14.0.tgz#359fabf5af403b3f128fe6ede3bff9754a9e18c4" - integrity sha512-iSwIR7kS/zwAzy/8S5cUMv2aceoJl/vIGhqmY9hSU0gVyzmsyaVnx00uNMvVDBUFiiPT2gonN8R3+dxg58TPaQ== +"@matrix-org/matrix-wysiwyg@^0.16.0": + version "0.16.0" + resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-0.16.0.tgz#2eb81899cedc740f522bd7c2839bd9151d67a28e" + integrity sha512-w+/bUQ5x4lVRncrYSmdxy5ww4kkgXeSg4aFfby9c7c6o/+o4gfV6/XBdoJ71nhStyIYIweKAz8i3zA3rKonyvw== "@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz": version "3.2.14"