From 122ef3fc03411fef379da4544cb44a6763b1e3c7 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 12 Oct 2022 01:46:20 +0200 Subject: [PATCH] Message Input: Open system context menu on second tap (#2068) --- .../middle/composer/MessageInput.tsx | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/middle/composer/MessageInput.tsx b/src/components/middle/composer/MessageInput.tsx index c4030a9de..cdd967d19 100644 --- a/src/components/middle/composer/MessageInput.tsx +++ b/src/components/middle/composer/MessageInput.tsx @@ -112,6 +112,7 @@ const MessageInput: FC = ({ const [isTextFormatterOpen, openTextFormatter, closeTextFormatter] = useFlag(); const [textFormatterAnchorPosition, setTextFormatterAnchorPosition] = useState(); const [selectedRange, setSelectedRange] = useState(); + const [isTextFormatterDisabled, setIsTextFormatterDisabled] = useState(false); useEffect(() => { if (!isAttachmentModalInput) return; @@ -161,6 +162,9 @@ const MessageInput: FC = ({ const selection = window.getSelection(); if (!selection || !selection.rangeCount || isContextMenuOpenRef.current) { closeTextFormatter(); + if (IS_ANDROID) { + setIsTextFormatterDisabled(false); + } return false; } @@ -185,6 +189,10 @@ const MessageInput: FC = ({ return; } + if (isTextFormatterDisabled) { + return; + } + const selectionRange = window.getSelection()!.getRangeAt(0); const selectionRect = selectionRange.getBoundingClientRect(); const inputRect = inputRef.current!.getBoundingClientRect(); @@ -299,13 +307,21 @@ const MessageInput: FC = ({ } } - function stopEvent(e: React.MouseEvent) { + function handleAndroidContextMenu(e: React.MouseEvent) { if (!checkSelection()) { return; } - e.preventDefault(); - e.stopPropagation(); + setIsTextFormatterDisabled(!isTextFormatterDisabled); + + if (!isTextFormatterDisabled) { + e.preventDefault(); + e.stopPropagation(); + + processSelection(); + } else { + closeTextFormatter(); + } } function updateInputHeight(willSend = false) { @@ -396,7 +412,7 @@ const MessageInput: FC = ({ onChange={handleChange} onKeyDown={handleKeyDown} onMouseDown={handleMouseDown} - onContextMenu={IS_ANDROID ? stopEvent : undefined} + onContextMenu={IS_ANDROID ? handleAndroidContextMenu : undefined} onTouchCancel={IS_ANDROID ? processSelectionWithTimeout : undefined} aria-label={placeholder} />