🔧 fix(constants.ts): add specialCharsRegex constant to match special characters in strings

🔧 fix(reactflowUtils.ts): update handleKeyDown function to prevent deletion of block when a special character is the last character in the input value
This commit is contained in:
Cristhian Zanforlin Lousa 2023-08-14 11:15:26 -03:00
commit 9acf9e39aa
2 changed files with 7 additions and 1 deletions

View file

@ -29,6 +29,7 @@ export const INVALID_CHARACTERS = [
*/
export const regexHighlight = /\{([^}]+)\}/g;
export const specialCharsRegex = /[!@#$%^&*()\-_=+[\]{}|;:'",.<>/?\\]/;
export const programmingLanguages: languageMap = {
javascript: ".js",

View file

@ -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<HTMLInputElement>, 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();
}