1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-12-20 20:42:03 +03:00

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
This commit is contained in:
Florian Duros
2023-01-11 18:56:01 +01:00
committed by GitHub
parent 07ae843709
commit 837115ece3
3 changed files with 16 additions and 8 deletions

View File

@@ -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<boolean>("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;
}