Skip to content

Fix: Auto-scroll to matching items when expanding tree nodes during search - #3

Draft
BenyaminBen wants to merge 1 commit into
masterfrom
upstream-pr-3407
Draft

Fix: Auto-scroll to matching items when expanding tree nodes during search#3
BenyaminBen wants to merge 1 commit into
masterfrom
upstream-pr-3407

Conversation

@BenyaminBen

@BenyaminBen BenyaminBen commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Mirror of codefori#3407 (author: @itsawaz)


Fix: Auto-scroll to matching items when expanding tree nodes during search

🐛 Problem

When using the Object Browser tree search functionality (Ctrl+F):

  • ✅ Search correctly highlights matching items in yellow
  • ❌ When expanding a collapsed node (Library/Source Physical File), the tree does NOT automatically scroll to reveal the first matching item
  • 😞 User must backspace and retype the search term to trigger the scroll (workaround)

This creates a poor user experience when searching through large object hierarchies.

✅ Solution

This PR implements automatic scroll-to-match functionality when tree nodes are expanded during an active search session.

What Changed

File: src/ui/views/objectBrowser.ts (+84 lines)

  1. Search State Tracking: Added currentSearchTerm field to ObjectBrowser class to track active search
  2. Expansion Event Handler: Added onDidExpandElement listener that:
    • Detects when nodes are expanded during search
    • Fetches children and finds first match (case-insensitive substring)
    • Calls reveal() to scroll the match into view
    • Uses 50ms delay to ensure DOM is rendered before revealing
  3. New Command: Added code-for-ibmi.setObjectBrowserSearchTerm as workaround for VS Code API limitation

How It Works

User Workflow:

  1. Run command: Code for IBM i: Set Object Browser Search Term
  2. Enter search term (e.g., "HELLO")
  3. Press Ctrl+F in Object Browser
  4. Type same term in search box
  5. Expand any collapsed node
  6. → First match automatically scrolls into view! 🎉

Technical Flow:
```
User expands node
→ onDidExpandElement fires
→ Check if search term exists
→ Get children from expanded node
→ Find first child matching search term
→ setTimeout(() => reveal(firstMatch), 50ms)
→ Tree scrolls to show the match
```

🤔 Why the Workaround Command?

VS Code's TreeView API doesn't expose the search term from the native `list.find` search box. The extension has no way to int... (truncated)

…earch

- Added search term tracking to ObjectBrowser class
- Implemented onDidExpandElement handler to detect node expansion
- Added reveal() call for first matching child with 50ms delay for DOM rendering
- Added 'Set Object Browser Search Term' command as workaround for VS Code API limitation

Fixes the issue where tree search highlights matches but doesn't scroll to them
when expanding collapsed nodes (libraries/source files).
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: d15748ea-9279-476a-9267-06646153d5d7

📥 Commits

Reviewing files that changed from the base of the PR and between 0c786aa and c3a565a.

📒 Files selected for processing (1)
  • src/ui/views/objectBrowser.ts

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.

@BenyaminBen

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

2 participants