Skip to content

Conversation

@yyhhyyyyyy
Copy link
Collaborator

@yyhhyyyyyy yyhhyyyyyy commented Aug 12, 2025

add ESC key to close floating chat window

Summary by CodeRabbit

  • New Features
    • Press Escape to instantly close the floating chat window.
    • Works across the app, reducing clicks and speeding navigation.
    • Consistent behavior across views without affecting other shortcuts.
    • Improves keyboard accessibility for users who prefer navigating without the mouse.
    • Closing the floating chat no longer requires targeting the close button, improving usability on smaller screens.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

Walkthrough

Introduces an IPC channel 'close-floating-window' in the main process to hide the floating chat window after validating the sender. Adds a renderer-level global Escape key handler that emits this IPC event. Registers/unregisters the key listener on mount/unmount. No other exported APIs or quit logic changed.

Changes

Cohort / File(s) Summary
Main IPC: Floating window control
src/main/presenter/windowPresenter/index.ts
Adds 'close-floating-window' IPC listener; verifies sender webContents.id matches floating chat window before invoking hideFloatingChatWindow(); registered alongside existing IPC handlers, before 'before-quit' logic.
Renderer: ESC key handling
src/renderer/src/App.vue
Adds global keydown handler; on Escape, sends 'close-floating-window' via IPC. Registers on mount; removes on unmount.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Renderer (App.vue)
  participant Main (WindowPresenter)
  participant FloatingChatWindow

  User->>Renderer (App.vue): Press Escape
  Renderer (App.vue)->>Main (WindowPresenter): IPC "close-floating-window"
  Main (WindowPresenter)->>Main (WindowPresenter): Validate sender matches floating window
  alt Sender matches
    Main (WindowPresenter)->>FloatingChatWindow: hideFloatingChatWindow()
  else Mismatch
    Main (WindowPresenter)->>Main (WindowPresenter): Ignore request
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A tap of ESC, a whisper in wire,
The window retreats, dimming its fire.
I’m a rabbit who loves tidy views—
Hop, hide, hush, on simple cues.
Little pane floats, then slips from sight,
Burrowed away—good night, good night. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/floating-window-esc-close

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (2)
src/renderer/src/App.vue (2)

189-190: Global keydown registration in App.vue is the wrong place for floating-window ESC.

Because the main process filters by sender (floating window only), this listener in the main shell does nothing for the floating window. Register the listener in the floating chat window’s renderer root and remove it here.

-  window.addEventListener('keydown', handleEscKey)

See rationale and presenter-based approach in the comment on Lines 172-178.


299-300: Unregister matches the added listener, but should be removed if you move the ESC logic.

If you relocate the ESC handler to the floating window’s renderer (recommended), remove this cleanup here as well.

-  window.removeEventListener('keydown', handleEscKey)

See the Lines 172-178 comment for the recommended approach.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f02aaaf and 9dc0eca.

📒 Files selected for processing (2)
  • src/main/presenter/windowPresenter/index.ts (1 hunks)
  • src/renderer/src/App.vue (3 hunks)
🧰 Additional context used
📓 Path-based instructions (15)
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Use English for logs and comments

Files:

  • src/renderer/src/App.vue
  • src/main/presenter/windowPresenter/index.ts
src/renderer/src/**/*.vue

📄 CodeRabbit Inference Engine (CLAUDE.md)

src/renderer/src/**/*.vue: Use Composition API for all Vue 3 components
Use Tailwind CSS with scoped styles for styling
Organize components by feature in src/renderer/src/
Follow existing component patterns in src/renderer/src/ when creating new UI components
Use Composition API with proper TypeScript typing for new UI components
Implement responsive design with Tailwind CSS for new UI components
Add proper error handling and loading states for new UI components

Use scoped styles to prevent CSS conflicts between components

Files:

  • src/renderer/src/App.vue
src/renderer/src/**/*.{ts,tsx,vue}

📄 CodeRabbit Inference Engine (CLAUDE.md)

src/renderer/src/**/*.{ts,tsx,vue}: Use Pinia for frontend state management
Renderer to Main: Use usePresenter.ts composable for direct presenter method calls

Files:

  • src/renderer/src/App.vue
src/renderer/src/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/i18n.mdc)

src/renderer/src/**/*: All user-facing strings must use i18n keys (avoid hardcoded user-visible text in code)
Use the 'vue-i18n' framework for all internationalization in the renderer
Ensure all user-visible text in the renderer uses the translation system

Files:

  • src/renderer/src/App.vue
src/renderer/**/*.{vue,ts,js,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)

渲染进程代码放在 src/renderer

Files:

  • src/renderer/src/App.vue
src/renderer/src/**/*.{vue,ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/vue-best-practices.mdc)

src/renderer/src/**/*.{vue,ts,tsx,js,jsx}: Use the Composition API for better code organization and reusability
Implement proper state management with Pinia
Utilize Vue Router for navigation and route management
Leverage Vue's built-in reactivity system for efficient data handling

Files:

  • src/renderer/src/App.vue
src/renderer/**/*.{ts,tsx,vue}

📄 CodeRabbit Inference Engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,tsx,vue}: Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
Use TypeScript for all code; prefer types over interfaces.
Avoid enums; use const objects instead.
Use arrow functions for methods and computed properties.
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.

Files:

  • src/renderer/src/App.vue
src/renderer/**/*.{vue,ts}

📄 CodeRabbit Inference Engine (.cursor/rules/vue-shadcn.mdc)

Implement lazy loading for routes and components.

Files:

  • src/renderer/src/App.vue
src/renderer/**/*.{ts,vue}

📄 CodeRabbit Inference Engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,vue}: Use useFetch and useAsyncData for data fetching.
Implement SEO best practices using Nuxt's useHead and useSeoMeta.

Files:

  • src/renderer/src/App.vue
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Strict type checking enabled for TypeScript

**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别

Files:

  • src/main/presenter/windowPresenter/index.ts
src/main/**/*.ts

📄 CodeRabbit Inference Engine (CLAUDE.md)

Main to Renderer: Use EventBus to broadcast events via mainWindow.webContents.send()

Use Electron's built-in APIs for file system and native dialogs

Files:

  • src/main/presenter/windowPresenter/index.ts
src/main/presenter/**/*.ts

📄 CodeRabbit Inference Engine (CLAUDE.md)

One presenter per functional domain

Files:

  • src/main/presenter/windowPresenter/index.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development-setup.mdc)

**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写

Files:

  • src/main/presenter/windowPresenter/index.ts
src/{main,renderer}/**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/electron-best-practices.mdc)

src/{main,renderer}/**/*.ts: Use context isolation for improved security
Implement proper inter-process communication (IPC) patterns
Optimize application startup time with lazy loading
Implement proper error handling and logging for debugging

Files:

  • src/main/presenter/windowPresenter/index.ts
src/main/**/*.{ts,js,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)

主进程代码放在 src/main

Files:

  • src/main/presenter/windowPresenter/index.ts
🧠 Learnings (2)
📚 Learning: 2025-07-21T01:45:54.229Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-07-21T01:45:54.229Z
Learning: Applies to src/renderer/src/composables/usePresenter.ts : The IPC in the renderer process is implemented in usePresenter.ts, allowing direct calls to the presenter-related interfaces exposed by the main process

Applied to files:

  • src/main/presenter/windowPresenter/index.ts
📚 Learning: 2025-07-21T01:45:54.229Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-07-21T01:45:54.229Z
Learning: Applies to src/main/presenter/index.ts : The IPC messages from the main process to notify the view mainly rely on the EventBus index.ts to listen for events that need to be notified and then send them to the renderer through the mainWindow

Applied to files:

  • src/main/presenter/windowPresenter/index.ts

Comment on lines +58 to +68
ipcMain.on('close-floating-window', (event) => {
// 检查发送者是否是悬浮聊天窗口
const webContentsId = event.sender.id
if (
this.floatingChatWindow &&
this.floatingChatWindow.getWindow()?.webContents.id === webContentsId
) {
this.hideFloatingChatWindow()
}
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Ad-hoc IPC channel bypasses presenter pattern and silently no-ops with current App.vue sender. Add error handling or switch to presenter.

  • Architecture: Renderer→Main should use usePresenter, not new raw ipcMain channels. Consider exposing hideFloatingChatWindow via the existing WindowPresenter bridge and calling it from the floating window’s renderer.
  • Functionality: Given App.vue is sending this event, your sender check will ignore it (webContents mismatch), so ESC won’t close the floating window. If you keep this IPC, mount the ESC handler in the floating window renderer.
  • Robustness: Add try-catch and explicit logs for unauthorized senders.

Apply this minimal hardening (if you keep the IPC):

-    ipcMain.on('close-floating-window', (event) => {
-      // 检查发送者是否是悬浮聊天窗口
-      const webContentsId = event.sender.id
-      if (
-        this.floatingChatWindow &&
-        this.floatingChatWindow.getWindow()?.webContents.id === webContentsId
-      ) {
-        this.hideFloatingChatWindow()
-      }
-    })
+    ipcMain.on('close-floating-window', (event) => {
+      try {
+        // Verify the sender is the floating chat window
+        const webContentsId = event.sender.id
+        const floatingId = this.floatingChatWindow?.getWindow()?.webContents.id
+        if (floatingId && floatingId === webContentsId) {
+          this.hideFloatingChatWindow()
+        } else {
+          console.debug(
+            `Ignoring "close-floating-window" from webContents ${webContentsId}; expected floating window ${floatingId}.`
+          )
+        }
+      } catch (err) {
+        console.error(
+          'Error handling "close-floating-window" IPC. Failed to hide floating chat window:',
+          err
+        )
+      }
+    })

Optional follow-ups:

  • Define the channel in your central events constants (e.g., WINDOW_EVENTS.CLOSE_FLOATING_WINDOW) instead of a string literal.
  • Prefer presenter-based calls for Renderer→Main and remove this IPC entirely once the floating window registers the ESC handler and calls windowPresenter.hideFloatingChatWindow().

To verify the mismatch causing a no-op, search where the ESC event is emitted and confirm sender IDs:


🏁 Script executed:

#!/bin/bash
# Show all emits of 'close-floating-window' in renderer
rg -n "ipcRenderer\\.send\\(['\"]close-floating-window['\"]" -A 2 -B 2 src/renderer || true

# Show the floating window webContents id when created (if logged)
rg -n "FloatingChatWindow.*webContents|getWindow\\(\\)\\?\\.webContents\\.id" -S src || true

Length of output: 588


#!/bin/bash

Verify that hideFloatingChatWindow is defined in the presenter

rg -n "hideFloatingChatWindow" -S src/main/presenter/windowPresenter/index.ts -A 5 -B 5


🏁 Script executed:

#!/bin/bash
# Locate implementation of hideFloatingChatWindow in the main presenter
rg -n "hideFloatingChatWindow" -S src/main/presenter -A5 -B5

# Verify if hideFloatingChatWindow is exposed via usePresenter in the renderer
rg -n "hideFloatingChatWindow" -S src/renderer/src/composables/usePresenter.ts -A5 -B5

Length of output: 1799


Refine close-floating-window IPC handling

The current ipcMain.on('close-floating-window', …) only hides the floating window when the sender’s WebContents ID matches the floating window, but your ESC handler lives in App.vue (main window). As a result, pressing Escape in the floating window won’t trigger hideFloatingChatWindow, and pressing it in the main window is intentionally ignored by your guard.

Code Locations:

  • src/main/presenter/windowPresenter/index.ts (lines 58–68): raw ipcMain listener
  • src/renderer/src/App.vue (lines 173–177): ESC → ipcRenderer.send('close-floating-window')
  • src/renderer/src/composables/usePresenter.ts: currently does not expose hideFloatingChatWindow

Actionable Fixes:

  1. Move/mirror your ESC key handler into the floating window’s renderer so its own WebContents can send the IPC.
  2. Or—preferably—expose hideFloatingChatWindow via your existing Presenter bridge:
    • Add hideFloatingChatWindow to usePresenter.ts
    • Call it directly from the floating‐window renderer instead of raw ipcRenderer.send(...)
  3. If you retain the IPC channel, harden it with error handling and logging:
   ipcMain.on('close-floating-window', (event) => {
-    // 检查发送者是否是悬浮聊天窗口
-    const webContentsId = event.sender.id
-    if (
-      this.floatingChatWindow &&
-      this.floatingChatWindow.getWindow()?.webContents.id === webContentsId
-    ) {
-      this.hideFloatingChatWindow()
-    }
+    try {
+      const senderId = event.sender.id
+      const floatId = this.floatingChatWindow?.getWindow()?.webContents.id
+      if (floatId === senderId) {
+        this.hideFloatingChatWindow()
+      } else {
+        console.debug(
+          `Ignored close-floating-window from ${senderId}, expected ${floatId}`
+        )
+      }
+    } catch (err) {
+      console.error('Failed to handle close-floating-window IPC:', err)
+    }

Optional Follow-Ups:

  • Define the channel in a central constant (e.g. WINDOW_EVENTS.CLOSE_FLOATING_WINDOW)
  • Remove the raw IPC listener once all floating-window callers use the Presenter API
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ipcMain.on('close-floating-window', (event) => {
// 检查发送者是否是悬浮聊天窗口
const webContentsId = event.sender.id
if (
this.floatingChatWindow &&
this.floatingChatWindow.getWindow()?.webContents.id === webContentsId
) {
this.hideFloatingChatWindow()
}
})
ipcMain.on('close-floating-window', (event) => {
try {
const senderId = event.sender.id
const floatId = this.floatingChatWindow?.getWindow()?.webContents.id
if (floatId === senderId) {
this.hideFloatingChatWindow()
} else {
console.debug(
`Ignored close-floating-window from ${senderId}, expected ${floatId}`
)
}
} catch (err) {
console.error('Failed to handle close-floating-window IPC:', err)
}
})
🤖 Prompt for AI Agents
In src/main/presenter/windowPresenter/index.ts around lines 58 to 68, the
ipcMain listener for 'close-floating-window' only hides the floating window when
the sender's webContents id matches the existing floating window, which prevents
the floating-window renderer (whose ESC handler should send the event) from
closing itself; fix this by adding a hideFloatingChatWindow method to the
renderer Presenter bridge (add to src/renderer/src/composables/usePresenter.ts
and implement a corresponding main-side handler) and update the floating-window
renderer to call presenter.hideFloatingChatWindow on ESC (or move the ESC
handler into the floating-window renderer), and if you keep the raw IPC channel,
relax the sender-id guard and add error handling/logging so attempts to close
are logged and safely ignored when no floating window exists.

Comment on lines +172 to +178
// 处理ESC键 - 关闭悬浮聊天窗口
const handleEscKey = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
window.electron.ipcRenderer.send('close-floating-window')
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

ESC handler in App.vue + raw IPC won’t close the floating window (sender check blocks it). Move to floating window and use presenter.

  • The IPC handler in main validates the sender is the floating chat window. App.vue runs in the main shell window, so pressing ESC here emits from the wrong WebContents and is ignored. Net result: ESC won’t close the floating window.
  • Renderer-to-Main should go through usePresenter, not ad-hoc IPC channels, per project guidelines.
  • Also, the new comment is not in English.

Apply this diff to improve correctness and align with guidelines (still in App.vue if you decide to keep it here), and make the comment English. Note: add windowPresenter (see snippet below).

-// 处理ESC键 - 关闭悬浮聊天窗口
-const handleEscKey = (event: KeyboardEvent) => {
-  if (event.key === 'Escape') {
-    window.electron.ipcRenderer.send('close-floating-window')
-  }
-}
+// Handle ESC key — close the floating chat window
+const handleEscKey = (event: KeyboardEvent) => {
+  if (event.key !== 'Escape' || event.isComposing || event.repeat) return
+  const active = document.activeElement as HTMLElement | null
+  const tag = active?.tagName?.toLowerCase()
+  const isTyping =
+    active?.isContentEditable ||
+    tag === 'input' ||
+    tag === 'textarea' ||
+    (active as HTMLInputElement)?.type === 'text'
+  if (isTyping) return
+  try {
+    windowPresenter.hideFloatingChatWindow()
+  } catch (err) {
+    console.error('[ERROR][App] Failed to hide floating chat window on ESC:', err)
+  }
+}

Additionally required (outside this hunk): declare the presenter once near your other presenters:

const windowPresenter = usePresenter('windowPresenter')

Recommended: register this ESC handler in the floating chat window’s renderer root instead of App.vue, to ensure ESC only closes when that window has focus and to avoid no-ops due to sender mismatch. If you prefer IPC, keep the handler in the floating window but call a typed presenter instead of raw IPC.

To confirm the current ESC listener runs in the floating window (it likely doesn’t), run:


🏁 Script executed:

#!/bin/bash
# 1) Find the FloatingChatWindow implementation and see what it loads
fd -t f -a FloatingChatWindow . | while read -r f; do
  echo "=== $f ==="
  rg -n "class FloatingChatWindow|load(File|URL)|index\.html" -A 5 -B 5 "$f"
done

# 2) Check if any renderer other than App.vue registers the ESC listener
rg -n "addEventListener\\(['\"]keydown['\"].*handleEscKey" -A 2 -B 2

# 3) Check whether App.vue is used by the floating renderer entry (often a different HTML/entry)
rg -n "renderer/.*/floating|floating.*index\\.html|Floating" -S src | sed -n '1,200p'

Length of output: 15467


🏁 Script executed:

#!/bin/bash
# 1) Search for 'close-floating-window' IPC channel usage
rg -n "close-floating-window" -S src

# 2) Find where ipcMain listens for raw IPC messages in main process
rg -n "ipcMain\.on" -S src/main
rg -n "ipcMain\.handle" -S src/main

Length of output: 871


🏁 Script executed:

#!/bin/bash
# Show handler implementation for 'close-floating-window' in windowPresenter
rg -n "ipcMain.on('close-floating-window'" -A5 -B5 src/main/presenter/windowPresenter/index.ts

Length of output: 198


🏁 Script executed:

#!/bin/bash
# Locate 'close-floating-window' handler in windowPresenter and show surrounding context
file="src/main/presenter/windowPresenter/index.ts"
line=$(grep -n "close-floating-window" "$file" | head -n1 | cut -d: -f1)
if [[ -n "$line" ]]; then
  start=$((line - 5))
  [[ $start -lt 1 ]] && start=1
  end=$((line + 5))
  sed -n "${start},${end}p" "$file"
else
  echo "Handler not found in $file"
fi

Length of output: 622


Use Presenter for ESC Handler & Scope to Floating Chat Window

The current ESC listener in App.vue sends a raw IPC message from the main shell window, which is ignored by the ipcMain handler in windowPresenter (it only accepts messages from the floating window’s WebContents). To fix this:

  • Replace ad-hoc IPC with the typed presenter API via usePresenter('windowPresenter').
  • Guard against event.isComposing, event.repeat, and typing contexts (input, textarea, contentEditable).
  • Register the handler only in the floating chat window’s renderer entry (under src/renderer/floating) so ESC only closes when that window is focused.

File: src/renderer/src/App.vue (L172–178), update:

-// 处理ESC键 - 关闭悬浮聊天窗口
-const handleEscKey = (event: KeyboardEvent) => {
-  if (event.key === 'Escape') {
-    window.electron.ipcRenderer.send('close-floating-window')
-  }
-}
+// Handle ESC key — close the floating chat window
+const handleEscKey = (event: KeyboardEvent) => {
+  if (event.key !== 'Escape' || event.isComposing || event.repeat) return
+  const active = document.activeElement as HTMLElement | null
+  const tag = active?.tagName?.toLowerCase()
+  const isTyping =
+    active?.isContentEditable ||
+    tag === 'input' ||
+    tag === 'textarea' ||
+    (active as HTMLInputElement)?.type === 'text'
+  if (isTyping) return
+  try {
+    windowPresenter.hideFloatingChatWindow()
+  } catch (err) {
+    console.error('[ERROR][App] Failed to hide floating chat window on ESC:', err)
+  }
+}

And near your other presenters, add:

const windowPresenter = usePresenter('windowPresenter')
🤖 Prompt for AI Agents
In src/renderer/src/App.vue around lines 172–178 the ESC handler sends a raw IPC
event from the main shell window which is ignored by the floating window
presenter; replace this with the typed presenter API by calling
usePresenter('windowPresenter') near your other presenters and invoke the
presenter's close method instead of sending raw ipc messages; add guards to the
keydown handler to return early if event.isComposing, event.repeat, or if the
active element is an input, textarea, or contentEditable to avoid interfering
with typing; and remove this global registration from the main shell — register
the handler only in the floating chat window renderer entry
(src/renderer/floating) so ESC only closes the floating window when it is
focused.

@zerob13 zerob13 merged commit b359f46 into dev Aug 12, 2025
2 checks passed
zerob13 added a commit that referenced this pull request Aug 13, 2025
* fix: add AlertDialogDescription to resolve accessibility warning (#706)

* fix: resolve focus flicker when creating new windows with Ctrl+Shift+N (#707)

* feat: enhance window management by implementing main window ID handling (#709)

* docs: update zhipu developer doc website link (#715)

Co-authored-by: gongchao <chao.gong@aminer.cn>

* refactor: better translate (#716)

* chore: en-us i18n

* chore(i18n): polish ja-JP translations across UI; keep chat.input.placeholder unchanged

* chore(i18n): polish fr-FR translations; keep chat.input.placeholder unchanged

* chore(i18n): refine fr-FR MCP & Settings copy; idiomatic, concise, brand-consistent

* chore(i18n): polish ru-RU translations across UI; keep chat.input.placeholder unchanged

* chore(i18n): polish fa-IR translations across UI; keep chat.input.placeholder unchanged

* chore: fix format

* chore: fix i18n

* chore: lock rolldown-vite version

* feat: add GPT-5 series model support (#717)

* ci(vite): Bundle the main file into a single file to speed up loading. (#718)

* fix(math): parser by upgrade vue-renderer-markdown (#722)

* chore: bump deps (#721)

* chore: bump deps

* fix: rolldown-vite 7.1.0 and duckdb bundle issue

* chore: back to vite

* chore: update electron

* chore: update versions

* fix(math): parser by upgrade vue-renderer-markdown (#722)

* chore: bump deps

---------

Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com>

* fix: add scrollable support to PopoverContent to prevent overflow (#720)

* feat: implement floating chat window system with performance optimization (#724)

* feat: add mcp sync and modelscope provider #615 (#723)

* wip: add modelscope provider

* feat: add mcp sync to modelscope

* fix: add scrollable support to PopoverContent to prevent overflow (#720)

* feat: implement floating chat window system with performance optimization (#724)

* chore: i18n and format

* feat: better style

* fix: mcp tool display

---------

Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com>

* fix: move_files newPath parse issue (#725)

* fix: move_files newPath 参数计算规则

* fix: move_files 移动前需要判断dest是目录还是文件

* feat: add Claude Opus 4.1 to anthropic default model list (#726)

* feat: Add mcprouter's MCP marketplace api support (#727)

* wip: add mcp market

* feat: mcp market install

* wip: mcp install status sync

* feat: mcp server config mask

* chore: remove working doc

* chore: add translate

* feat: add ESC key to close floating chat window (#728)

* feat: add floating button position persistence with boundary validation (#729)

* feat: add floating button position persistence with boundary validation

* feat: refactor floating button to use electron-window-state

* chore: bump to 0.3.0

* feat: add reasoning_effort parameter support for gpt-oss models (#731)

* feat: add reasoning_effort parameter support for gpt-oss models

- add reasoning effort UI support across all components

* fix: preserve user reasoning effort settings and improve display logic

* fix: artifacts code not streaming (#732)

* fix: artifact react load failed

* chore: remove log

* fix: artifacts code not stream

* fix: format

---------

Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com>
Co-authored-by: hllshiro <40970081+hllshiro@users.noreply.github.com>
Co-authored-by: tomsun28 <tomsun28@outlook.com>
Co-authored-by: gongchao <chao.gong@aminer.cn>
Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com>
Co-authored-by: wanna <wanna.w@binarywalk.com>
zerob13 added a commit that referenced this pull request Aug 13, 2025
* fix: add AlertDialogDescription to resolve accessibility warning (#706)

* fix: resolve focus flicker when creating new windows with Ctrl+Shift+N (#707)

* feat: enhance window management by implementing main window ID handling (#709)

* docs: update zhipu developer doc website link (#715)

Co-authored-by: gongchao <chao.gong@aminer.cn>

* refactor: better translate (#716)

* chore: en-us i18n

* chore(i18n): polish ja-JP translations across UI; keep chat.input.placeholder unchanged

* chore(i18n): polish fr-FR translations; keep chat.input.placeholder unchanged

* chore(i18n): refine fr-FR MCP & Settings copy; idiomatic, concise, brand-consistent

* chore(i18n): polish ru-RU translations across UI; keep chat.input.placeholder unchanged

* chore(i18n): polish fa-IR translations across UI; keep chat.input.placeholder unchanged

* chore: fix format

* chore: fix i18n

* chore: lock rolldown-vite version

* feat: add GPT-5 series model support (#717)

* ci(vite): Bundle the main file into a single file to speed up loading. (#718)

* fix(math): parser by upgrade vue-renderer-markdown (#722)

* chore: bump deps (#721)

* chore: bump deps

* fix: rolldown-vite 7.1.0 and duckdb bundle issue

* chore: back to vite

* chore: update electron

* chore: update versions

* fix(math): parser by upgrade vue-renderer-markdown (#722)

* chore: bump deps

---------

Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com>

* fix: add scrollable support to PopoverContent to prevent overflow (#720)

* feat: implement floating chat window system with performance optimization (#724)

* feat: add mcp sync and modelscope provider #615 (#723)

* wip: add modelscope provider

* feat: add mcp sync to modelscope

* fix: add scrollable support to PopoverContent to prevent overflow (#720)

* feat: implement floating chat window system with performance optimization (#724)

* chore: i18n and format

* feat: better style

* fix: mcp tool display

---------

Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com>

* fix: move_files newPath parse issue (#725)

* fix: move_files newPath 参数计算规则

* fix: move_files 移动前需要判断dest是目录还是文件

* feat: add Claude Opus 4.1 to anthropic default model list (#726)

* feat: Add mcprouter's MCP marketplace api support (#727)

* wip: add mcp market

* feat: mcp market install

* wip: mcp install status sync

* feat: mcp server config mask

* chore: remove working doc

* chore: add translate

* feat: add ESC key to close floating chat window (#728)

* feat: add floating button position persistence with boundary validation (#729)

* feat: add floating button position persistence with boundary validation

* feat: refactor floating button to use electron-window-state

* chore: bump to 0.3.0

* feat: add reasoning_effort parameter support for gpt-oss models (#731)

* feat: add reasoning_effort parameter support for gpt-oss models

- add reasoning effort UI support across all components

* fix: preserve user reasoning effort settings and improve display logic

* fix: artifacts code not streaming (#732)

* fix: artifact react load failed

* chore: remove log

* fix: artifacts code not stream

* fix: format

* feat: disable automatic model enabling for better UX (#734)

* feat: sync provider sorting from settings to model selection (#736)

* feat: sync provider sorting from settings to model selection

* feat: refactor ModelSelect to use computed providers for better reactivity

---------

Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com>
Co-authored-by: hllshiro <40970081+hllshiro@users.noreply.github.com>
Co-authored-by: tomsun28 <tomsun28@outlook.com>
Co-authored-by: gongchao <chao.gong@aminer.cn>
Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com>
Co-authored-by: wanna <wanna.w@binarywalk.com>
@zerob13 zerob13 deleted the feat/floating-window-esc-close branch November 23, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants