Skip to content

Conversation

@TCOTC
Copy link
Contributor

@TCOTC TCOTC commented Sep 13, 2025

改进在大纲拖拽时自动翻页

之前是一顿一顿的:

video.webm

修改之后可以持续滚动:

video.webm

感觉文档树和编辑器的自动翻页 #12461 也能用类似的方法来优化,不过还是等这个 PR 合并了再看看

@88250 88250 requested a review from Vanessa219 October 16, 2025 02:20
@88250
Copy link
Member

88250 commented Oct 16, 2025

提交的变更好像有问题,只有一个文件变化,麻烦看看。

image

@TCOTC
Copy link
Contributor Author

TCOTC commented Oct 16, 2025

@88250 我这里 GitHub 看到是有三处变更的,你确认一下:

image

@88250
Copy link
Member

88250 commented Oct 16, 2025

现在好了。

@Vanessa219 审核一下

@88250 88250 added this to the 3.3.6 milestone Oct 16, 2025
@Vanessa219 Vanessa219 merged commit b3b5bbb into siyuan-note:dev Oct 20, 2025
@Vanessa219 Vanessa219 requested a review from Copilot October 20, 2025 03:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Improves automatic scrolling behavior during drag operations in the outline view by replacing jerky step-by-step scrolling with smooth continuous scrolling. The change enhances user experience by providing consistent frame-rate-aware scrolling animation.

  • Replaced single-step scrolling with continuous animation using requestAnimationFrame
  • Added frame rate calculation to ensure consistent scroll speed across different devices
  • Implemented fallback mechanism for browsers without requestAnimationFrame support

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +388 to +389
// 如果还没有开始滚动,则开始持续滚动
if (!this.scrollAnimationId) {
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The logic for checking scroll boundaries and starting animation is nested deeply within the existing drag logic. Consider extracting the scroll animation logic into a separate private method to improve code organization and readability.

Copilot uses AI. Check for mistakes.
}

// 每隔 20 帧重新计算一次帧率
if (scrollFrameCount % 20 === 0) {
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic number 20 for frame calculation interval should be extracted as a named constant to improve code maintainability and make the logic clearer.

Copilot uses AI. Check for mistakes.
Comment on lines +408 to +410
// 基于当前帧率计算滚动步长,确保等效于 60fps 时的 16px/帧
const baseScrollStep = 16;
const targetFPS = 60;
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

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

[nitpick] Magic numbers 16 (scroll step) and 60 (target FPS) should be extracted as named constants, possibly as class properties or module constants, to improve maintainability.

Copilot uses AI. Check for mistakes.
} else {
// 回退到 setTimeout 方法
const scrollInterval = 16; // 约 60fps
const scrollStep = 16; // 每次滚动的距离
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The fallback implementation duplicates the scroll step value (16) from the main animation logic. Consider using the same constants defined earlier to avoid code duplication.

Suggested change
const scrollStep = 16; // 每次滚动的距离
const scrollStep = Constants.SIZE_SCROLL_STEP; // 每次滚动的距离

Copilot uses AI. Check for mistakes.
Comment on lines +479 to +487
// 清理滚动动画
if (this.scrollAnimationId) {
if (typeof cancelAnimationFrame !== "undefined") {
cancelAnimationFrame(this.scrollAnimationId);
} else {
clearTimeout(this.scrollAnimationId);
}
this.scrollAnimationId = null;
}
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The scroll animation cleanup logic is duplicated in two places (lines 440-447 and 480-487). Consider extracting this into a private method to reduce code duplication.

Copilot uses AI. Check for mistakes.
@Vanessa219
Copy link
Member

测试了一下,以下情况不会进行滚动:

  1. 速度快一点
  2. 不在固定区域
Jietu20251020-112748-HD.mp4

我先回滚了,后面修改好后重新提交即可。

@Vanessa219 Vanessa219 removed this from the 3.3.6 milestone Oct 20, 2025
@TCOTC TCOTC deleted the feat/outline branch October 20, 2025 06:09
@TCOTC
Copy link
Contributor Author

TCOTC commented Oct 20, 2025

不用回滚,不然等会我 PR 需要合并冲突会有点麻烦

@TCOTC
Copy link
Contributor Author

TCOTC commented Oct 20, 2025

#16161

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