From 9b7ef55ad73c4398ba223d81f5e780daefdd4aee Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Tue, 23 Apr 2024 21:43:01 +0800 Subject: [PATCH] adjustment: simplified caret helper --- .../InfisicalSecretInput.tsx | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx index 29e91f110..965a24761 100644 --- a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx +++ b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx @@ -98,18 +98,14 @@ export const InfisicalSecretInput = forwardRef( const [lastCaretPos, setLastCaretPos] = useState(0); const isCaretInsideReference = (str: string, start: number) => { - const matches = [...str.matchAll(REGEX_SECRET_REFERENCE_FIND)]; - for (let i = 0; i < matches.length; i += 1) { - const match = matches[i]; - if ( - typeof match?.index !== "undefined" && - match.index <= start && - start < match.index + match[0].length - ) { - return match; - } - } - return null; + const match = [...str.matchAll(REGEX_SECRET_REFERENCE_FIND)].find( + (entry) => + typeof entry?.index !== "undefined" && + entry.index <= start && + start < entry.index + entry[0].length + ); + + return match || null; }; const setCaretPos = (caretPos: number) => {