Skip to content

Commit 61211fe

Browse files
floriandurosandybalaam
authored andcommitted
Fix unexpected composer growing (matrix-org#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
1 parent 49c118e commit 61211fe

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"dependencies": {
5858
"@babel/runtime": "^7.12.5",
5959
"@matrix-org/analytics-events": "^0.4.0",
60-
"@matrix-org/matrix-wysiwyg": "^0.14.0",
60+
"@matrix-org/matrix-wysiwyg": "^0.16.0",
6161
"@matrix-org/react-sdk-module-api": "^0.0.3",
6262
"@sentry/browser": "^7.0.0",
6363
"@sentry/tracing": "^7.0.0",

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { WysiwygInputEvent } from "@matrix-org/matrix-wysiwyg";
17+
import { WysiwygEvent } from "@matrix-org/matrix-wysiwyg";
1818
import { useCallback } from "react";
1919

2020
import { useSettingValue } from "../../../../../hooks/useSettings";
2121

2222
export function useInputEventProcessor(onSend: () => void) {
2323
const isCtrlEnter = useSettingValue<boolean>("MessageComposerInput.ctrlEnterToSend");
2424
return useCallback(
25-
(event: WysiwygInputEvent) => {
25+
(event: WysiwygEvent) => {
2626
if (event instanceof ClipboardEvent) {
2727
return event;
2828
}
2929

30-
if ((event.inputType === "insertParagraph" && !isCtrlEnter) || event.inputType === "sendMessage") {
30+
const isKeyboardEvent = event instanceof KeyboardEvent;
31+
const isEnterPress =
32+
!isCtrlEnter && (isKeyboardEvent ? event.key === "Enter" : event.inputType === "insertParagraph");
33+
// sendMessage is sent when ctrl+enter is pressed
34+
const isSendMessage = !isKeyboardEvent && event.inputType === "sendMessage";
35+
36+
if (isEnterPress || isSendMessage) {
37+
event.stopPropagation?.();
38+
event.preventDefault?.();
3139
onSend();
3240
return null;
3341
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,10 +1589,10 @@
15891589
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-js/-/matrix-sdk-crypto-js-0.1.0-alpha.2.tgz#a09d0fea858e817da971a3c9f904632ef7b49eb6"
15901590
integrity sha512-oVkBCh9YP7H9i4gAoQbZzswniczfo/aIptNa4dxRi4Ff9lSvUCFv6Hvzi7C+90c0/PWZLXjIDTIAWZYmwyd2fA==
15911591

1592-
"@matrix-org/matrix-wysiwyg@^0.14.0":
1593-
version "0.14.0"
1594-
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-0.14.0.tgz#359fabf5af403b3f128fe6ede3bff9754a9e18c4"
1595-
integrity sha512-iSwIR7kS/zwAzy/8S5cUMv2aceoJl/vIGhqmY9hSU0gVyzmsyaVnx00uNMvVDBUFiiPT2gonN8R3+dxg58TPaQ==
1592+
"@matrix-org/matrix-wysiwyg@^0.16.0":
1593+
version "0.16.0"
1594+
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-0.16.0.tgz#2eb81899cedc740f522bd7c2839bd9151d67a28e"
1595+
integrity sha512-w+/bUQ5x4lVRncrYSmdxy5ww4kkgXeSg4aFfby9c7c6o/+o4gfV6/XBdoJ71nhStyIYIweKAz8i3zA3rKonyvw==
15961596

15971597
"@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz":
15981598
version "3.2.14"

0 commit comments

Comments
 (0)