Skip to content
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

feat(editor): add a preference prevent scroll after get focused #3846

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

bytemain
Copy link
Member

@bytemain bytemain commented Jul 12, 2024

Types

  • 🎉 New Features

Background or solution

点击 tab 的时候,会调用 group.open(uri, {focus: true}),该方法内部调用了 Element.prototype.focus, 这个方法会使得元素被滚动到视图
image

image

Changelog

add a preference that can prevent scroll after editor get focus

Summary by CodeRabbit

  • 新功能

    • 添加了 MouseEventButton 常量,用于表示不同的鼠标按键。
    • IResourceOpenOptions 接口中新增了 preventScroll 属性。
    • customEditorSchema 中新增了 editor.preventScrollAfterFocused 属性。
  • 改进

    • BrowserClipboardService 类中的 focus() 方法现在包含 preventScroll: true 参数。
    • MonacoCommandRegistry 类中的 execute 方法现在直接返回 monacoHandler.execute 的结果。
    • IconService 类中的 listen 方法改用 onSpecificPreferenceChange 进行事件处理。
  • 修复

    • 调整了 tab.view.tsx 中的滚动行为处理,以及鼠标事件处理的逻辑。

Copy link

railway-app bot commented Jul 12, 2024

🚅 Previously deployed to Railway in the core project. Environment has been deleted.

@bytemain
Copy link
Member Author

/next

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

这些更改引入了多个模块的若干改进,包括新增了鼠标事件按钮常量、在不同位置增加了防止滚动选项、改变了一些事件处理逻辑以及引入了新的配置属性。这些变更整体上提升了代码的可维护性和功能性。

Changes

文件路径 更改摘要
packages/core-browser/src/dom/index.ts 新增 MouseEventButton 常量,用于表示不同的鼠标按钮。
packages/core-browser/src/services/clipboard.service.ts BrowserClipboardService 类中的 focus() 方法增加了 preventScroll: true 参数。
packages/core-common/src/settings/general.ts GeneralSettingsId 枚举从 const enum 改为 enum
packages/editor/src/browser/monaco-contrib/command/command.service.ts MonacoCommandRegistry 类中的 execute 方法直接返回 monacoHandler.execute 的结果。
packages/editor/src/browser/tab.view.tsx 引入 MouseEventButton 并调整了选项卡的滚动行为及鼠标事件处理逻辑。
packages/editor/src/browser/workbench-editor.service.ts EditorGroup 类中的 doOpenfocus 方法增加了 preventScroll 选项检查。
packages/editor/src/common/editor.ts IResourceOpenOptions 接口中新增 preventScroll 属性。
packages/terminal-next/src/browser/component/tab.item.tsx 移除了 renderInfoItem 函数中的 appConfig 声明。
packages/theme/src/browser/icon.service.ts IconService 类中 listen 方法改用 onSpecificPreferenceChange 并更新了事件处理逻辑。
packages/editor/src/browser/preference/schema.ts customEditorSchema 中新增 editor.preventScrollAfterFocused 属性。

Sequence Diagram(s)

默默忽略该部分,因为变更过于简单或多样化,不适合生成序列图。


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@opensumi opensumi bot added the 🎨 feature feature required label Jul 12, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5ece2fb and e25feac.

Files selected for processing (9)
  • packages/core-browser/src/dom/index.ts (1 hunks)
  • packages/core-browser/src/services/clipboard.service.ts (1 hunks)
  • packages/core-common/src/settings/general.ts (1 hunks)
  • packages/editor/src/browser/monaco-contrib/command/command.service.ts (1 hunks)
  • packages/editor/src/browser/tab.view.tsx (3 hunks)
  • packages/editor/src/browser/workbench-editor.service.ts (6 hunks)
  • packages/editor/src/common/editor.ts (1 hunks)
  • packages/terminal-next/src/browser/component/tab.item.tsx (1 hunks)
  • packages/theme/src/browser/icon.service.ts (1 hunks)
Files skipped from review due to trivial changes (4)
  • packages/editor/src/browser/monaco-contrib/command/command.service.ts
  • packages/editor/src/browser/tab.view.tsx
  • packages/editor/src/common/editor.ts
  • packages/terminal-next/src/browser/component/tab.item.tsx
Additional comments not posted (10)
packages/core-common/src/settings/general.ts (1)

Line range hint 1-6:
更改 const enum 为标准 enum

此更改将 const enum 转换为标准 enum。这可能是为了提高兼容性或提供更多的灵活性。

packages/core-browser/src/services/clipboard.service.ts (2)

38-40: 添加 preventScroll 选项到 focus 调用

textArea.focus 调用中添加 preventScroll: true 选项,以防止聚焦时自动滚动到视图中。这符合 PR 的目标,防止自动滚动行为。


46-48: 添加 preventScroll 选项到 focus 调用

activeElement.focus 调用中添加 preventScroll: true 选项,以防止聚焦时自动滚动到视图中。这符合 PR 的目标,防止自动滚动行为。

packages/core-browser/src/dom/index.ts (1)

178-188: 添加 MouseEventButton 常量

新常量 MouseEventButton 提供了鼠标按键类型的清晰枚举,提高了代码的可读性和可维护性。

packages/theme/src/browser/icon.service.ts (1)

98-104: 使用 onSpecificPreferenceChange 处理偏好设置更改

使用 onSpecificPreferenceChange 而不是 onPreferenceChanged 提高了偏好设置更改处理的特异性和效率。

packages/editor/src/browser/workbench-editor.service.ts (5)

1347-1350: 新增方法:获取 preventScroll 选项

这个方法从提供的选项或偏好服务中检索 preventScroll 选项。代码看起来正确且逻辑清晰。


1374-1377: 添加 preventScroll 选项到焦点方法

doOpen 方法中,代码现在在聚焦 DOM 节点之前检查并设置 preventScroll 选项。代码看起来正确且逻辑清晰。


1623-1624: 添加 preventScroll 选项到焦点方法

openCodeEditor 方法中,代码现在在聚焦 DOM 节点之前检查并设置 preventScroll 选项。代码看起来正确且逻辑清晰。


1676-1679: 添加 preventScroll 选项到焦点方法

openDiffEditor 方法中,代码现在在聚焦 DOM 节点之前检查并设置 preventScroll 选项。代码看起来正确且逻辑清晰。


2208-2208: 添加 preventScroll 选项到焦点方法

focus 方法中,代码现在使用 getPreventScrollOption 方法来处理 preventScroll 逻辑。代码看起来正确且逻辑清晰。

@opensumi
Copy link
Contributor

opensumi bot commented Jul 12, 2024

🎉 PR Next publish successful!

3.1.5-next-1720766832.0

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5ece2fb and e25feac.

Files selected for processing (9)
  • packages/core-browser/src/dom/index.ts (1 hunks)
  • packages/core-browser/src/services/clipboard.service.ts (1 hunks)
  • packages/core-common/src/settings/general.ts (1 hunks)
  • packages/editor/src/browser/monaco-contrib/command/command.service.ts (1 hunks)
  • packages/editor/src/browser/tab.view.tsx (3 hunks)
  • packages/editor/src/browser/workbench-editor.service.ts (6 hunks)
  • packages/editor/src/common/editor.ts (1 hunks)
  • packages/terminal-next/src/browser/component/tab.item.tsx (1 hunks)
  • packages/theme/src/browser/icon.service.ts (1 hunks)
Files skipped from review due to trivial changes (5)
  • packages/core-browser/src/dom/index.ts
  • packages/core-common/src/settings/general.ts
  • packages/editor/src/browser/monaco-contrib/command/command.service.ts
  • packages/editor/src/common/editor.ts
  • packages/terminal-next/src/browser/component/tab.item.tsx
Additional comments not posted (11)
packages/core-browser/src/services/clipboard.service.ts (2)

38-40: 确保 focus 方法中的 preventScroll 选项正确使用

在调用 textArea.focus 方法时,添加了 preventScroll: true 选项,以防止页面滚动。此更改是合适的,但请确保在所有相关场景中都需要此行为。


46-48: 确保 focus 方法中的 preventScroll 选项正确使用

在调用 activeElement.focus 方法时,添加了 preventScroll: true 选项,以防止页面滚动。此更改是合适的,但请确保在所有相关场景中都需要此行为。

packages/theme/src/browser/icon.service.ts (1)

98-104: 更新监听方法以使用 onSpecificPreferenceChange

此更改将 listen 方法从 onPreferenceChanged 更新为 onSpecificPreferenceChange,并在应用主题之前检查 iconContributionRegistry。这增强了事件处理逻辑。

packages/editor/src/browser/tab.view.tsx (4)

25-25: 引入 MouseEventButton 常量

引入 MouseEventButton 常量以标准化鼠标按钮值。这是一个良好的实践,有助于提高代码的可读性和维护性。


176-179: 防止标签获取焦点时滚动

在调用 scrollIntoView 方法时,添加了 block: 'nearest'inline: 'nearest' 选项,以防止标签获取焦点时滚动。请确保此更改符合预期行为。


432-432: 使用 MouseEventButton.Middle 常量

更新 onMouseUp 事件处理程序以使用 MouseEventButton.Middle 常量,而不是检查 e.nativeEvent.which === 2。此更改提高了代码的一致性和可读性。


439-439: 使用 MouseEventButton.Left 常量

更新 onMouseDown 事件处理程序以使用 MouseEventButton.Left 常量,而不是检查 e.nativeEvent.which === 1。此更改提高了代码的一致性和可读性。

packages/editor/src/browser/workbench-editor.service.ts (4)

1347-1350: 代码通过,但请验证偏好设置的使用情况

这个新函数getPreventScrollOption实现了从IResourceOpenOptions或偏好设置中获取preventScroll选项的功能。建议检查偏好设置是否在代码库的其他部分正确设置和使用。


1623-1624: 代码通过,但请验证 preventScroll 的使用

openCodeEditor 函数中添加了对 getPreventScrollOption 的调用,并在 focus 调用中使用了 preventScroll 选项。建议确保在 focus 调用中正确使用 preventScroll

Verification successful

代码通过,但请验证 preventScroll 的使用

openCodeEditor 函数中添加了对 getPreventScrollOption 的调用,并在 focus 调用中使用了 preventScroll 选项。建议确保在 focus 调用中正确使用 preventScroll

  • zone-widget.ts: activeElement?.focus({ preventScroll: true });
  • workbench-editor.service.ts: this._domNode?.focus({ preventScroll });
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify `preventScroll` usage in focus calls.

# Test: Search for `focus` calls with `preventScroll` option. Expect: Occurrences of `preventScroll` usage in focus calls.
rg --type js --type ts --pattern 'focus\(\s*\{[^}]*preventScroll'

Length of output: 479


Script:

#!/bin/bash
# Description: Verify `preventScroll` usage in focus calls.

# Test: Search for `focus` calls with `preventScroll` option. Expect: Occurrences of `preventScroll` usage in focus calls.
rg 'focus\(\s*\{[^}]*preventScroll' --type js --type ts

Length of output: 264


1374-1377: 代码通过,但请验证 preventScroll 的使用

doOpen 函数中添加了对 getPreventScrollOption 的调用,并使用了 preventScroll 选项。建议确保在 focus 调用中正确使用 preventScroll

Verification successful

代码通过,但请验证 preventScroll 的使用

doOpen 函数中添加了对 getPreventScrollOption 的调用,并使用了 preventScroll 选项。经验证,focus 调用中的 preventScroll 选项在代码库中正确使用。

  • packages/monaco-enhance/src/browser/zone-widget.ts
  • packages/editor/src/browser/workbench-editor.service.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify `preventScroll` usage in focus calls.

# Test: Search for `focus` calls with `preventScroll` option. Expect: Occurrences of `preventScroll` usage in focus calls.
rg --type js --type ts --pattern 'focus\(\s*\{[^}]*preventScroll'

Length of output: 479


Script:

#!/bin/bash
# Description: Verify `preventScroll` usage in focus calls.

# Test: Search for `focus` calls with `preventScroll` option. Expect: Occurrences of `preventScroll` usage in focus calls.
rg 'focus\(\s*\{[^}]*preventScroll' --type js --type ts

Length of output: 264


1676-1679: 代码通过,但请验证 preventScroll 的使用

openDiffEditor 函数中添加了对 getPreventScrollOption 的调用,并在 focus 调用中使用了 preventScroll 选项。建议确保在 focus 调用中正确使用 preventScroll

Verification successful

代码通过,但请验证 preventScroll 的使用

openDiffEditor 函数中添加了对 getPreventScrollOption 的调用,并在 focus 调用中使用了 preventScroll 选项。建议确保在 focus 调用中正确使用 preventScroll

  • packages/monaco-enhance/src/browser/zone-widget.ts 文件中有类似的 preventScroll 使用方式。
  • packages/editor/src/browser/workbench-editor.service.ts 文件中正确使用了 preventScroll
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify `preventScroll` usage in focus calls.

# Test: Search for `focus` calls with `preventScroll` option. Expect: Occurrences of `preventScroll` usage in focus calls.
rg --type js --type ts --pattern 'focus\(\s*\{[^}]*preventScroll'

Length of output: 479


Script:

#!/bin/bash
# Description: Verify `preventScroll` usage in focus calls.

# Test: Search for `focus` calls with `preventScroll` option.
rg --type js --type ts 'focus\(\s*\{[^}]*preventScroll'

Length of output: 264

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 47.05882% with 9 lines in your changes missing coverage. Please review.

Project coverage is 55.00%. Comparing base (3e0fe4e) to head (37e9106).

Files Patch % Lines
...ges/editor/src/browser/workbench-editor.service.ts 55.55% 2 Missing and 2 partials ⚠️
packages/theme/src/browser/icon.service.ts 25.00% 2 Missing and 1 partial ⚠️
...ges/core-browser/src/services/clipboard.service.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3846   +/-   ##
=======================================
  Coverage   54.99%   55.00%           
=======================================
  Files        1556     1557    +1     
  Lines       94800    94813   +13     
  Branches    19406    19409    +3     
=======================================
+ Hits        52132    52148   +16     
+ Misses      35451    35450    -1     
+ Partials     7217     7215    -2     
Flag Coverage Δ
jsdom 50.43% <47.05%> (+<0.01%) ⬆️
node 15.56% <11.76%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Outside diff range, codebase verification and nitpick comments (1)
packages/editor/src/browser/preference/schema.ts (1)

1501-1505: 缺少本地化键 %editor.configuration.preventScrollAfterFocused%

请确保在适当的本地化文件中添加此键,以便正确翻译描述。

  • 更新 packages/editor/src/browser/preference/schema.ts 文件中添加的描述键。
Analysis chain

新添加的偏好设置 editor.preventScrollAfterFocused 看起来不错!

请确保描述 %editor.configuration.preventScrollAfterFocused% 已正确本地化。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the localization key for `editor.preventScrollAfterFocused` is defined.

# Test: Search for the localization key. Expect: The key should be defined.
rg '%editor.configuration.preventScrollAfterFocused%'

Length of output: 171


Script:

#!/bin/bash
# Description: Verify the localization key for `editor.preventScrollAfterFocused` is defined in localization files.

# Test: Search for the localization key in all localization files. Expect: The key should be defined.
rg '%editor.configuration.preventScrollAfterFocused%' --glob '*local*'

Length of output: 70


Script:

#!/bin/bash
# Description: Perform a targeted search for the localization key in specific localization files.

# Test: Search for the localization key in known localization directories. Expect: The key should be defined.
rg '%editor.configuration.preventScrollAfterFocused%' --glob 'packages/**/locales/*'

Length of output: 233


Script:

#!/bin/bash
# Description: Perform a broader search for the localization key and debug why files might be skipped.

# Test: Search for the localization key in all files and use debug mode to understand any issues.
rg '%editor.configuration.preventScrollAfterFocused%' --debug

Length of output: 12413

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e25feac and f427b5f.

Files selected for processing (1)
  • packages/editor/src/browser/preference/schema.ts (1 hunks)

@bytemain
Copy link
Member Author

/next

1 similar comment
@bytemain
Copy link
Member Author

/next

@opensumi
Copy link
Contributor

opensumi bot commented Jul 12, 2024

🎉 PR Next publish successful!

3.1.5-next-1720770997.0

@bytemain bytemain merged commit abf93e5 into main Jul 15, 2024
13 checks passed
@bytemain bytemain deleted the feat/prevent-editor-scroll branch July 15, 2024 02:25
@bytemain
Copy link
Member Author

这个配置在以下场景中非常有用:

  • OpenSumi 被嵌入在网页中的某一部分

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants