From 03aaabc9566903a40e3346f93fd0863ee02a6750 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Sat, 11 Jan 2025 17:06:43 -0500 Subject: [PATCH] debounce are you sure deletions --- components/Blocks/useBlockKeyboardHandlers.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/Blocks/useBlockKeyboardHandlers.ts b/components/Blocks/useBlockKeyboardHandlers.ts index e3eccc88..7fa09927 100644 --- a/components/Blocks/useBlockKeyboardHandlers.ts +++ b/components/Blocks/useBlockKeyboardHandlers.ts @@ -114,6 +114,7 @@ function ArrowUp({ e, props }: Args) { if (!prevBlock) return; } +let debounced: null | number = null; async function Backspace({ e, props, @@ -140,6 +141,9 @@ async function Backspace({ // ...and areYouSure state is false, set it to true if (!areYouSure) { setAreYouSure(true); + debounced = window.setTimeout(() => { + debounced = null; + }, 300); return; } // ... and areYouSure state is true, @@ -147,6 +151,13 @@ async function Backspace({ // if there is a page to close, close it and remove the block if (areYouSure) { e.preventDefault(); + if (debounced) { + window.clearTimeout(debounced); + debounced = window.setTimeout(() => { + debounced = null; + }, 300); + return; + } return deleteBlock([props.entityID].flat(), rep); } } -- 2.51.2