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: support inline input restore #4345

Merged
merged 1 commit into from
Feb 7, 2025
Merged

Conversation

Ricbet
Copy link
Member

@Ricbet Ricbet commented Feb 7, 2025

Types

  • 🎉 New Features

Background or solution

例如切换文件时,可以恢复成上次未关闭时的 inline input

inline_input_restore.mp4

Changelog

inline input 在输入状态下支持恢复

Summary by CodeRabbit

  • 重构
    • 调整了聊天组件的行为,现在在编辑器布局变化时不会自动隐藏,确保组件持续可见。
  • 新特性
    • 增强了输入组件,新增了对输入值变化的支持,并改进了状态管理,提高交互响应。
  • 样式
    • 优化了Logo容器布局,实现内容居中对齐并处理溢出,改善整体视觉效果。

@Ricbet Ricbet requested review from hacke2 and erha19 February 7, 2025 08:33
@Ricbet Ricbet self-assigned this Feb 7, 2025
@opensumi opensumi bot added the 🎨 feature feature required label Feb 7, 2025
@Ricbet
Copy link
Member Author

Ricbet commented Feb 7, 2025

/next

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

本次 PR 主要涉及三大块调整:首先,在内嵌聊天组件中移除了监听编辑器布局变化以自动处理隐藏状态的代码;其次,在内嵌输入组件中引入了新的 onValueChange 属性以及事件发射器,并对类名和事件逻辑进行了调整;最后,在内嵌输入的控制器中加入了 observables 来管理输入状态及模型变化,同时新增了两个用于管理不同输入场景的 store 类。此外,还对部分 CSS 样式进行了布局优化。

Changes

文件路径 修改摘要
packages/ai-native/src/browser/widget/inline-chat/…/inline-content-widget.tsx 移除监听编辑器布局变化的代码,取消了 widget 超出视区时自动 dispose 的逻辑。
packages/ai-native/src/browser/widget/inline-input/… (inline-input-widget.tsx, inline-input.controller.ts, model.ts) 为内嵌输入组件新增 onValueChange 属性和事件发射器,调整类名(InlineInputChatWidget → InlineInputWidget),并引入 observables 及新的输入状态管理 store 类以改进输入状态管理。
packages/core-browser/src/components/ai-native/ai-action/index.module.less 修改 .logo_container 的 CSS,添加 overflow:hidden、display:flex、justify-content:center 和 align-items:center 属性以优化布局和居中显示。

Sequence Diagram(s)

sequenceDiagram
    participant 用户 as User
    participant Widget as InlineInputWidget
    participant Controller as InlineInputController
    participant Store as WidgetStore

    用户->>Widget: 输入文本
    Widget->>Controller: 触发 onValueChange 事件
    Controller->>Store: 更新输入状态与存储数据
    Store-->>Controller: 通知状态变化
    Controller->>Widget: 更新组件显示或隐藏
Loading

Possibly related PRs

Suggested labels

🎨 feature, 💄 style change

Suggested reviewers

  • bytemain

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...
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 (Beta)

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>, please review it.
    • 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 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 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 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. (Beta)
  • @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 (4)
packages/ai-native/src/browser/widget/inline-input/inline-input.controller.ts (4)

70-75: 新增核心属性:inputValue、modelChangeObs、inlineInputWidgetStore。

  1. inputValue 用于追踪输入内容变化。
  2. modelChangeObs 与编辑器模型变动绑定。
  3. 使用 Map 存储各模型对应的 widget 状态时,需确保编辑器销毁时正确清理,以免造成内存泄漏。

82-87: 初始化 observable 属性。
通过 observableValue 和 observableFromEvent 来管理输入和模型变更,尽量在组件或控制器销毁时一起 dispose 以防止潜在资源泄漏。


140-159: autorun 监听 modelChangeObs 并根据 storeData 状态显示或隐藏输入。

  1. autorun 可自动收集依赖,但要确认在 dispose 时也能终止观察。
  2. storeData 的类型分支处理合理,保证了不同存储类的场景各自对应。

197-197: 通过依赖注入获取 InlineInputWidget 实例。
建议关注依赖注入的对象范围,避免注入过多非必要依赖。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbe3bc and 888e545.

📒 Files selected for processing (5)
  • packages/ai-native/src/browser/widget/inline-chat/inline-content-widget.tsx (0 hunks)
  • packages/ai-native/src/browser/widget/inline-input/inline-input-widget.tsx (4 hunks)
  • packages/ai-native/src/browser/widget/inline-input/inline-input.controller.ts (22 hunks)
  • packages/ai-native/src/browser/widget/inline-input/model.ts (2 hunks)
  • packages/core-browser/src/components/ai-native/ai-action/index.module.less (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/ai-native/src/browser/widget/inline-chat/inline-content-widget.tsx
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: build-windows
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (40)
packages/ai-native/src/browser/widget/inline-input/inline-input.controller.ts (31)

18-24: 引入可观察对象相关依赖的更新正常。
这些 observable 工具可以帮助管理输入值和模型变更,使用上看不出问题。


38-38: 替换为新的 InlineInputWidget 导入。
单一更改,未发现问题。


41-41: 导入空行与选区两种存储类。
显式区分两种场景,逻辑更清晰。


115-115: 监听 onHidden 事件并隐藏输入。
逻辑简单直接,与业务相符。


172-172: 清除当前模型在 inlineInputWidgetStore 中的记录。
调用 delete 操作前,需要确保 this.monacoEditor.getModel() 不为 null。


188-190: 在空行场景下设置默认值并记录到 Store。
在输入时即可保留用户输入的初始内容,为后续恢复提供便利。


217-217: 设置 inlineInputWidgetIsVisible 上下文键为 true。
展示状态与上下文联动,整体流程正常。


221-224: 在 onDispose 时执行取消操作并清理装饰。
确认与 hideInput() 之间的调用顺序和作用是否会产生重复或冲突。


229-238: onValueChange 同步输入值并存储到空行场景对象。
能实时更新 store 数据,保证状态一致性。


239-273: onResultClick 处理多种结果选项。
针对不同的结果类型实现了重生、接受、丢弃等逻辑,整体完善。


265-266: 在重新生成时再次调用 showInputInEmptyLine。
可连续重试,符合需求。


310-311: onSend 处理输入发送的主逻辑。
流程清晰,无明显缺陷。


320-321: 启动 THINKING 状态。
状态管理明确,后续互斥流程也能稳定继续。


336-336: 异常取消后将状态重置为 READY。
保证组件能重新处理下一次输入。


369-369: 错误时切换到 ERROR 状态。
实现了基础的错误可视化逻辑。


374-374: 结束流式输入后状态为 DONE。
向用户直观地呈现处理已完成。


379-379: 再次结束流式输入后状态为 DONE。
流程的完整度较高,避免多次操作混乱。


388-388: 将 inlineInputWidget 注册到 inputDisposable 中。
及时 dispose 可以防止资源泄露。


397-404: 在选区场景也先确认 model 是否存在。
流程与空行类似,避免模型空引用问题。


423-425: 在选区模式下通过 inlineInputWidget.show() 展示组件。
可见状态被正确更新并存储,用法合理。


430-431: onDispose 中执行取消操作与资源清理。
逻辑与空行模式保持一致,整合较好。


438-446: onValueChange 保存选区场景的值到 store。
保证在选区模式中的输入也能被实时追踪。


448-449: onClose 时隐藏输入。
终止逻辑正常,没有多余操作。


460-461: onSend 处理选区情况下的策略分支。
隐藏输入或继续预览的逻辑清晰。


483-483: 终止预览时重置为 READY 状态。
很好的清理与状态恢复机制。


499-499: 出现错误时切换到 ERROR 状态。
与空行的异常处理保持一致。


503-503: onAbort 后切换为 DONE 状态。
有助于给用户明显的流式结束信号。


507-507: onEnd 时切换为 DONE 状态。
与上一处类似,保证流程彻底结束。


516-517: mount 方法将 inlineInputWidget 挂到 diffPreviewer。
实现可视化差异预览与输入组件的联动。


519-519: 未使用预览策略时恢复 READY。
对无预览策略的场景处理到位。


533-533: 再次显示选区输入实现“再生成”场景。
支持用户在同一选区多次生成输入,很灵活。

packages/ai-native/src/browser/widget/inline-input/model.ts (3)

3-3: 更新 import 以包含 IPosition 与 Selection。
满足空行和选区两种输入场景的位置信息需求。


36-54: 新增 InlineInputWidgetStoreInEmptyLine。
该类用来记录空行模式输入的行位置与输入字符串,为后续恢复提供基础。


56-74: 新增 InlineInputWidgetStoreInSelection。
该类用来记录选区模式下的 Selection 与输入值,可精准恢复用户操作。

packages/ai-native/src/browser/widget/inline-input/inline-input-widget.tsx (5)

24-24: 为 IInlineInputWidgetRenderProps 新增 onValueChange。
支持对用户输入实时监听,改进可用性。


28-29: 解构并使用 onValueChange 属性。
保持组件参数一致性,增强易读性。


92-93: 重命名并添加 Emitter:_onSend / onSend。
统一了命名方式,语义更明确。


98-100: 新增事件 _onValueChange / onValueChange。
实现对输入中间态的监听,丰富了事件处理能力。


114-130: 在 renderView 中将 onValueChange 与 onSend 绑定到组件。

  1. onValueChange 调用 _onValueChange.fire(value),确保外部能实时同步值。
  2. onSend 调用 _onSend.fire(value) 并切换状态为 THINKING,流程通畅。
packages/core-browser/src/components/ai-native/ai-action/index.module.less (1)

52-55: 新增样式确保居中与溢出隐藏
这部分修改在.logo_container内添加了 overflow: hidden; display: flex; justify-content: center; 和 align-items: center;。这确保了内部元素(例如图标)在容器内能够水平、垂直居中显示,同时隐藏任何意外溢出的内容,有助于提升组件的整体视觉一致性。请确认在不同设备和分辨率下,这些设置不会意外截断应显示的内容,也确保其与内嵌输入恢复功能的其他交互组件在布局上保持协调。

@opensumi
Copy link
Contributor

opensumi bot commented Feb 7, 2025

🎉 PR Next publish successful!

3.7.1-next-1738917599.0

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 0% with 92 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@7fbe3bc). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ser/widget/inline-input/inline-input.controller.ts 0.00% 63 Missing and 9 partials ⚠️
...ai-native/src/browser/widget/inline-input/model.ts 0.00% 20 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4345   +/-   ##
=======================================
  Coverage        ?   54.15%           
=======================================
  Files           ?     1639           
  Lines           ?   100301           
  Branches        ?    21760           
=======================================
  Hits            ?    54323           
  Misses          ?    38204           
  Partials        ?     7774           
Flag Coverage Δ
jsdom 49.64% <0.00%> (?)
node 12.28% <0.00%> (?)

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
Member

@hacke2 hacke2 left a comment

Choose a reason for hiding this comment

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

LGTM

@Ricbet Ricbet merged commit 512420a into main Feb 7, 2025
14 checks passed
@Ricbet Ricbet deleted the feat/inline-input-restore branch February 7, 2025 09:11
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.

3 participants