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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
}