diff --git a/src/components/middle/composer/MessageInput.tsx b/src/components/middle/composer/MessageInput.tsx
index ac6ca0494..825f5f526 100644
--- a/src/components/middle/composer/MessageInput.tsx
+++ b/src/components/middle/composer/MessageInput.tsx
@@ -58,6 +58,8 @@ type StateProps = {
const MAX_INPUT_HEIGHT = IS_SINGLE_COLUMN_LAYOUT ? 256 : 416;
const TAB_INDEX_PRIORITY_TIMEOUT = 2000;
+// Heuristics allowing the user to make a triple click
+const SELECTION_RECALCULATE_DELAY_MS = 260;
const TEXT_FORMATTER_SAFE_AREA_PX = 90;
// For some reason Safari inserts `
` after user removes text from input
const SAFARI_BR = '
';
@@ -103,6 +105,8 @@ const MessageInput: FC = ({
// eslint-disable-next-line no-null/no-null
const inputRef = useRef(null);
// eslint-disable-next-line no-null/no-null
+ const selectionTimeoutRef = useRef(null);
+ // eslint-disable-next-line no-null/no-null
const cloneRef = useRef(null);
const lang = useLang();
@@ -207,8 +211,11 @@ const MessageInput: FC = ({
}
function processSelectionWithTimeout() {
+ if (selectionTimeoutRef.current) {
+ window.clearTimeout(selectionTimeoutRef.current);
+ }
// Small delay to allow browser properly recalculate selection
- setTimeout(processSelection, 1);
+ selectionTimeoutRef.current = window.setTimeout(processSelection, SELECTION_RECALCULATE_DELAY_MS);
}
function handleMouseDown(e: React.MouseEvent) {