Skip to content

fix: get close tab shortcut from key-binding-registry #4606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bubkoo
Copy link

@bubkoo bubkoo commented Jul 18, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background or solution

fix #4604

Changelog

Summary by CodeRabbit

  • 改进
    • 编辑器标签页关闭按钮的提示信息现在会动态显示当前实际的快捷键组合,而非固定为平台默认(如⌘W或Ctrl+W)。如果未设置快捷键,则仍会显示默认值。

@opensumi opensumi bot added the 🐞 bug Something isn't working label Jul 18, 2025
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


pengxingjian seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

Walkthrough

本次更改优化了编辑器标签页关闭按钮的提示信息,动态获取并显示“editor.close”命令的实际快捷键,而不再根据平台硬编码为“⌘W”或“Ctrl+W”。其余组件和服务逻辑保持不变。

Changes

文件路径 变更摘要
packages/design/src/browser/override/editor-tab.service.tsx 动态获取“editor.close”命令的快捷键,并在关闭标签页按钮的提示中显示,替换原有的硬编码方式。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EditorTabCloseComponent
    participant KeybindingRegistry

    User->>EditorTabCloseComponent: 鼠标悬停关闭按钮
    EditorTabCloseComponent->>KeybindingRegistry: 查询"editor.close"快捷键
    KeybindingRegistry-->>EditorTabCloseComponent: 返回快捷键信息
    EditorTabCloseComponent-->>User: 显示包含实际快捷键的提示信息
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
(node:12453) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for url.parse() vulnerabilities.
(Use node --trace-deprecation ... to show where the warning was created)
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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: 0

🧹 Nitpick comments (2)
packages/design/src/browser/override/editor-tab.service.tsx (2)

23-26: 实现逻辑正确,但可以进行优化

动态获取快捷键的实现逻辑正确,成功替代了硬编码的平台特定快捷键。不过有几个改进建议:

  1. 第25行可以使用可选链操作符来简化代码
  2. 逻辑清晰,正确处理了回退情况

应用以下优化:

-  const keyBinds = keybindingRegistry.getKeybindingsForCommand('editor.close');
-  const keyBinding = keyBinds && keyBinds[0];
+  const keyBinding = keybindingRegistry.getKeybindingsForCommand('editor.close')?.[0];

27-27: 考虑 useMemo 依赖数组

useMemo 的依赖数组为空,但计算依赖于 shortCut 变量。如果运行时可能动态更新快捷键绑定,建议将 shortCut 添加到依赖数组中。

-  const title = useMemo(() => formatLocalize('editor.closeTab.title', shortCut), []);
+  const title = useMemo(() => formatLocalize('editor.closeTab.title', shortCut), [shortCut]);

如果快捷键绑定在运行时是静态的,当前实现也是可以接受的。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be6af37 and 1df6f8d.

📒 Files selected for processing (1)
  • packages/design/src/browser/override/editor-tab.service.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/design/src/browser/override/editor-tab.service.tsx (1)
Learnt from: bytemain
PR: opensumi/core#4088
File: packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx:73-74
Timestamp: 2024-10-12T07:43:08.790Z
Learning: 在 `LivePreviewDiffDecorationModel` 类(位于 `packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx`)中,通过依赖注入(`@Autowired`)从 module 的 `providers` 声明中获取的依赖(如 `_onPartialEditEvent`),其销毁逻辑由 `ClientApp` 的生命周期管理,不需要手动调用 `dispose()` 进行销毁。
🪛 Biome (1.9.4)
packages/design/src/browser/override/editor-tab.service.tsx

[error] 25-25: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (1)
packages/design/src/browser/override/editor-tab.service.tsx (1)

4-4: 导入变更正确

正确添加了 KeybindingRegistry 导入,这是实现动态获取快捷键功能所必需的。

@Ricbet
Copy link
Member

Ricbet commented Jul 18, 2025

LGTM。
感谢 pr,麻烦签一下 CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

关闭 Tab 快捷键写死了
3 participants