From 31834d56b5d73e70ef5becc721ac716faebe68c4 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 20 Jul 2022 16:02:20 +0200 Subject: [PATCH] Composer: Support triple click to select all (#1963) --- src/components/middle/composer/MessageInput.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) {