Skip to content

TreeView: click on off‑screen item scrolls back to last selected item (GitLens, TODO Tree, custom TreeViews) #17002

@panjetaa

Description

@panjetaa

Bug Description:

There is a focus/scroll issue in Theia’s implementation of [vscode.TreeView]. When clicking a tree item that is currently not visible (off‑screen), the scrollbar sometimes jumps back to the last selected item instead of selecting and executing the command for the clicked item.

This reproduces in multiple extensions that use TreeView, e.g. GitLens and TODO Tree, and also in our own TreeView-based extension. The same extensions behave correctly in VS Code.

Steps to Reproduce:

This is easiest to see with GitLens or TODO Tree, but also happens in our custom TreeView:

  1. Open a workspace with enough items in a TreeView so that the view is scrollable (e.g. many TODOs, GitLens repository/file history, or our logical project view).
  2. Select an item that is near the bottom of the view so that the scrollbar is scrolled down.
  3. Close all editors so that the editor area is empty.
  4. Scroll the TreeView up so that a different item (near the top) is visible, but the previously selected item is off‑screen.
  5. Single‑click the newly visible item.

Actual Behavior

Occasionally (not 100% reproducible, but frequent enough):

  • The scrollbar jumps back to the previously selected item (the one that was off‑screen).
  • The command associated with the clicked TreeView item is not executed (e.g. our [handleFileClick] is not called, TODO Tree item not opened, GitLens item not opened).
  • It feels like the first click is consumed only to restore/focus the previous selection, and the actual click is “lost”.

This happens:

More often when no editor is open (editor area completely empty).
With multiple TreeView-based extensions (GitLens, TODO Tree, our own), which suggests a host issue rather than an extension bug.

Notes / Observations

In our own TreeView, we log inside the item command handler (handleFileClick bound via TreeItem.command). When the bug occurs, that handler is never called, confirming that the command is not fired at all.
The issue only appears under Theia. The same extensions and code behave correctly in VS Code (no unexpected scroll, commands always fire).
It seems related to focus/selection handling when:
The editor area is empty, and
The last selected TreeView item is off‑screen.
Request

Could you please investigate the TreeView focus/selection behavior in Theia when clicking an item that is not currently selected and partially/fully off‑screen? The expectation is that the click both selects the item and triggers its command, without unexpected scroll back to the previous selection.

Theia version: 1.68.0

2026-02-16_14-05-52.scrollbar.jumps.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbugs found in the applicationtreeissues related to the tree (ex: tree widget)vscodeissues related to VSCode compatibility

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions