Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: handle backspace navigating back on desktop app

Andrew Bastin1b36de4fa3fa
diff --git a/packages/hoppscotch-selfhost-desktop/src/main.ts b/packages/hoppscotch-selfhost-desktop/src/main.ts
index 1205e59cc..53b98548b 100644
--- a/packages/hoppscotch-selfhost-desktop/src/main.ts
+++ b/packages/hoppscotch-selfhost-desktop/src/main.ts
@@ -96,3 +96,29 @@ const headerPaddingTop = ref("0px")
headerPaddingLeft.value = "70px"
}
})()
+
+
+function isTextInput(target: EventTarget | null) {
+ if (target instanceof HTMLInputElement) {
+ return target.type === 'text'
+ || target.type === 'email'
+ || target.type === 'password'
+ || target.type === 'number'
+ || target.type === 'search'
+ || target.type === 'tel'
+ || target.type === 'url'
+ || target.type === 'textarea'
+ } else if (target instanceof HTMLTextAreaElement) {
+ return true
+ } else if (target instanceof HTMLElement && target.isContentEditable) {
+ return true
+ }
+
+ return false
+}
+
+window.addEventListener('keydown',function(e){
+ if (e.key === "Backspace" && !isTextInput(e.target)) {
+ e.preventDefault()
+ }
+},true);