From 9acf9e39aac4c11dc34726a27682073957b89425 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 14 Aug 2023 11:15:26 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(constants.ts):=20add=20speci?= =?UTF-8?q?alCharsRegex=20constant=20to=20match=20special=20characters=20i?= =?UTF-8?q?n=20strings=20=F0=9F=94=A7=20fix(reactflowUtils.ts):=20update?= =?UTF-8?q?=20handleKeyDown=20function=20to=20prevent=20deletion=20of=20bl?= =?UTF-8?q?ock=20when=20a=20special=20character=20is=20the=20last=20charac?= =?UTF-8?q?ter=20in=20the=20input=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/constants/constants.ts | 1 + src/frontend/src/utils/reactflowUtils.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index 0ff77cf45..68730bbf9 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -29,6 +29,7 @@ export const INVALID_CHARACTERS = [ */ export const regexHighlight = /\{([^}]+)\}/g; +export const specialCharsRegex = /[!@#$%^&*()\-_=+[\]{}|;:'",.<>/?\\]/; export const programmingLanguages: languageMap = { javascript: ".js", diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 0b3449b45..ae7de3f0d 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -4,6 +4,7 @@ import { APITemplateType } from "../types/api"; import { FlowType, NodeType } from "../types/flow"; import { cleanEdgesType } from "../types/utils/reactflowUtils"; import { toNormalCase } from "./utils"; +import { specialCharsRegex } from "../constants/constants"; export function cleanEdges({ flow: { edges, nodes }, @@ -235,7 +236,11 @@ export function addVersionToDuplicates(flow: FlowType, flows: FlowType[]) { export function handleKeyDown(e: React.KeyboardEvent, inputValue: string | string[] | null, block: string) { - if (typeof inputValue === "string" && e.ctrlKey && e.key === "Backspace" && (inputValue === block || inputValue?.charAt(inputValue?.length - 1) === ' ')) { + + if (typeof inputValue === "string" && e.ctrlKey && e.key === "Backspace" && + (inputValue === block || inputValue?.charAt(inputValue?.length - 1) === ' ' + || specialCharsRegex.test(inputValue?.charAt(inputValue?.length - 1)) + )) { e.preventDefault(); e.stopPropagation(); }