Просмотр исходного кода

fix(app): keep Escape handling local to prompt input on macOS desktop (#13963)

Ganesh 6 месяцев назад
Родитель
Сommit
0186a85063
1 измененных файлов с 30 добавлено и 10 удалено
  1. 30 10
      packages/app/src/components/prompt-input.tsx

+ 30 - 10
packages/app/src/components/prompt-input.tsx

@@ -280,6 +280,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
   }
 
   const isFocused = createFocusSignal(() => editorRef)
+  const escBlur = () => platform.platform === "desktop" && platform.os === "macos"
 
   const closePopover = () => setStore("popover", null)
 
@@ -842,13 +843,39 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
         return
       }
     }
-    if (store.mode === "shell") {
-      const { collapsed, cursorPosition, textLength } = getCaretState()
-      if (event.key === "Escape") {
+
+    if (event.key === "Escape") {
+      if (store.popover) {
+        closePopover()
+        event.preventDefault()
+        event.stopPropagation()
+        return
+      }
+
+      if (store.mode === "shell") {
         setStore("mode", "normal")
         event.preventDefault()
+        event.stopPropagation()
+        return
+      }
+
+      if (working()) {
+        abort()
+        event.preventDefault()
+        event.stopPropagation()
+        return
+      }
+
+      if (escBlur()) {
+        editorRef.blur()
+        event.preventDefault()
+        event.stopPropagation()
         return
       }
+    }
+
+    if (store.mode === "shell") {
+      const { collapsed, cursorPosition, textLength } = getCaretState()
       if (event.key === "Backspace" && collapsed && cursorPosition === 0 && textLength === 0) {
         setStore("mode", "normal")
         event.preventDefault()
@@ -927,13 +954,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     if (event.key === "Enter" && !event.shiftKey) {
       handleSubmit(event)
     }
-    if (event.key === "Escape") {
-      if (store.popover) {
-        closePopover()
-      } else if (working()) {
-        abort()
-      }
-    }
   }
 
   return (