Skip to content

Conversation

@GinirohikoCha
Copy link

  • 为缩略图添加引用以便精确滚动定位
  • 添加键盘事件监听器支持方向键切换幻灯片
  • 实现切换幻灯片时滚动条自动滚动到当前选中项

- 为缩略图添加引用以便精确滚动定位
- 添加键盘事件监听器支持方向键切换幻灯片
- 实现切换幻灯片时滚动条自动滚动到当前选中项
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @GinirohikoCha, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在增强幻灯片预览页面的用户体验,通过引入键盘导航功能,用户可以更便捷地浏览幻灯片。同时,为了配合键盘导航,还实现了缩略图列表的自动滚动功能,确保用户在切换幻灯片时能够直观地看到当前选中的缩略图,从而提升了交互的流畅性和可用性。

Highlights

  • 键盘导航: 为幻灯片预览页面添加了键盘事件监听器,允许用户使用方向键(上下左右)切换幻灯片。
  • 缩略图自动滚动: 实现了当幻灯片切换时,侧边栏的缩略图列表会自动滚动,确保当前选中的缩略图始终可见。
  • 引用管理: 引入了 useRef 钩子来管理缩略图列表容器和每个缩略图项的引用,以便精确控制滚动行为。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

你好,感谢你的贡献!这次的 PR 实现了键盘导航和缩略图自动滚动功能,整体实现得很好。我注意到一个小问题,全局键盘事件监听器可能会在用户输入文本时意外触发幻灯片切换。我提供了一个建议来修复这个问题。此外,代码中有很多纯粹的格式化更改(例如,删除空行),建议在未来的提交中将功能性更改和格式化更改分开,以便于审查。总的来说,这是一次很棒的功能增强!

Comment on lines 169 to 186
const handleKeyDown = (e: KeyboardEvent) => {
if (!currentProject || currentProject.pages.length === 0) return;

switch (e.key) {
case 'ArrowLeft':
case 'ArrowUp':
e.preventDefault();
setSelectedIndex((prev) => Math.max(0, prev - 1));
break;
case 'ArrowRight':
case 'ArrowDown':
e.preventDefault();
setSelectedIndex((prev) => Math.min(currentProject.pages.length - 1, prev + 1));
break;
default:
break;
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

全局键盘事件监听器没有检查当前焦点是否在输入框内。当用户在文本框(如编辑弹窗中的输入框)中使用方向键移动光标时,会意外地触发幻灯片切换,影响用户体验。建议在处理键盘事件前,先判断活动元素是否为输入控件。

    const handleKeyDown = (e: KeyboardEvent) => {
      const activeElement = document.activeElement as HTMLElement;
      if (activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA' || activeElement.isContentEditable)) {
        return;
      }

      if (!currentProject || currentProject.pages.length === 0) return;

      switch (e.key) {
        case 'ArrowLeft':
        case 'ArrowUp':
          e.preventDefault();
          setSelectedIndex((prev) => Math.max(0, prev - 1));
          break;
        case 'ArrowRight':
        case 'ArrowDown':
          e.preventDefault();
          setSelectedIndex((prev) => Math.min(currentProject.pages.length - 1, prev + 1));
          break;
        default:
          break;
      }
    };

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.

1 participant