You've already forked matrix-react-sdk
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user