adjustment: simplified caret helper

This commit is contained in:
Sheen Capadngan
2024-04-23 21:43:01 +08:00
parent 872f8bdad8
commit 9b7ef55ad7

View File

@@ -98,18 +98,14 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
const [lastCaretPos, setLastCaretPos] = useState<number>(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) => {