Skip to content

feat: package code file tree should keep active file in view#1977

Merged
ghostdevv merged 11 commits into
npmx-dev:mainfrom
btea:feat/file-tree-scoll-to-active-node
Jul 7, 2026
Merged

feat: package code file tree should keep active file in view#1977
ghostdevv merged 11 commits into
npmx-dev:mainfrom
btea:feat/file-tree-scoll-to-active-node

Conversation

@btea

@btea btea commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Scroll the active file in the files list into view when it's clicked/page loaded

🧭 Context

📚 Description

When switching files in the code file tree area, the selected file will automatically jump to the center of the area.

@vercel

vercel Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Jul 7, 2026 2:35am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Jul 7, 2026 2:35am
npmx-lunaria Ignored Ignored Jul 7, 2026 2:35am

Request Review

@codecov

codecov Bot commented Mar 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/components/Code/FileTree.vue 83.33% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai

coderabbitai Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a treeRoot ref to the file tree, queries the active node via aria-current="true", and scrolls it into view after currentPath changes and ancestor expansion completes.

Changes

File tree current-node scrolling

Layer / File(s) Summary
Root ref, scroll helper, and watcher
app/components/Code/FileTree.vue
Creates a treeRoot template ref, binds it to the root <ul>, and adds watcher logic that expands ancestors then scrolls the active node into view.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is on-topic and describes the same file-tree auto-scroll behaviour.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: keeping the active file in the code file tree in view.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fb857c39-22d7-4d7d-bdb1-c3dad6a02d27

📥 Commits

Reviewing files that changed from the base of the PR and between 0d952fa and 30a4dce.

📒 Files selected for processing (1)
  • app/components/Code/FileTree.vue

Comment thread app/components/Code/FileTree.vue

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
app/components/Code/FileTree.vue (1)

40-45: Consider using generic querySelector for type safety.

The type assertion as HTMLElement works but could be tightened. Using the generic form avoids a cast and aligns with the coding guideline for strictly type-safe code.

Suggested improvement
 const scrollIntoView = () => {
-  const el = treeRoot.value?.querySelector('[aria-current="true"]') as HTMLElement
+  const el = treeRoot.value?.querySelector<HTMLElement>('[aria-current="true"]')
   if (el) {
     el.scrollIntoView({ block: 'center' })
   }
 }

As per coding guidelines: "Ensure you write strictly type-safe code, for example by ensuring you always check when accessing an array value by index."


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 52934022-cdcd-4f8b-b5df-3d63f0824666

📥 Commits

Reviewing files that changed from the base of the PR and between 30a4dce and ab14372.

📒 Files selected for processing (1)
  • app/components/Code/FileTree.vue

@ghostdevv ghostdevv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is an interesting bug where if you load the page on a small screen when it scrolls the scroll isn't contained to the file tree

@btea

btea commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

I tested it with the preview link, and when I clicked the icon in the lower right corner to expand the side tree structure, it correctly retrieved the node and scrolled the node into the view area.

@ghostdevv ghostdevv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can't reproduce the scroll issue I had a couple weeks back, so LGTM!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
app/components/Code/FileTree.vue (1)

45-50: ⚠️ Potential issue | 🟠 Major

Run the path watcher only from the root tree instance.

At Line 45, this watcher still executes in every recursive CodeFileTree instance. That can queue repeated nextTick(scrollIntoView) calls (Line 50) and redundant autoExpandAncestors work on each path change.

Proposed fix
 watch(
   () => props.currentPath,
   path => {
-    if (path) {
+    if (path && depth.value === 0) {
       autoExpandAncestors(path)
       nextTick(scrollIntoView)
     }
   },
   { immediate: true },
 )

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 95746bab-bc3a-40d5-ae1f-f6c1e2a49c9e

📥 Commits

Reviewing files that changed from the base of the PR and between 57eec3e and 0a0d6da.

📒 Files selected for processing (1)
  • app/components/Code/FileTree.vue

@ghostdevv ghostdevv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah wait, it seems to still scroll even when the thing is already visible 🤔

@btea

btea commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

In this case, the smooth effect should probably be removed.

@ghostdevv

Copy link
Copy Markdown
Member

In this case, the smooth effect should probably be removed.

The smooth made it much more obvious but it happens without it 🫠

@btea

btea commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

That's true. But I think the silky smooth scrolling effect looks good right now. 😄

@ghostdevv

Copy link
Copy Markdown
Member

Blocked by #2288 for now, as the solution for that will help make this work 🙏

@github-actions github-actions Bot added stale This has become stale and may be closed soon and removed stale This has become stale and may be closed soon labels May 10, 2026
@github-actions github-actions Bot added the stale This has become stale and may be closed soon label Jun 10, 2026
@github-actions github-actions Bot closed this Jun 17, 2026
@btea

btea commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@ghostdevv Can this PR be restarted?

@ghostdevv ghostdevv reopened this Jun 27, 2026
@gameroman gameroman removed stale This has become stale and may be closed soon stale-to-close labels Jun 27, 2026
@ghostdevv ghostdevv force-pushed the feat/file-tree-scoll-to-active-node branch from 16c1191 to 8a75324 Compare July 7, 2026 02:34
@ghostdevv ghostdevv changed the title feat: code file tree switch file to active node feat: package code file tree should keep active file in view Jul 7, 2026
@ghostdevv ghostdevv added this pull request to the merge queue Jul 7, 2026
Merged via the queue into npmx-dev:main with commit 3b651c2 Jul 7, 2026
25 checks passed
@btea btea deleted the feat/file-tree-scoll-to-active-node branch July 7, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front Frontend, Design

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants