Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tree] It would be beneficial to separate Tree node selection from node toggling #1433

Closed
vsajip opened this issue Dec 23, 2022 · 7 comments · Fixed by #1700
Closed

[Tree] It would be beneficial to separate Tree node selection from node toggling #1433

vsajip opened this issue Dec 23, 2022 · 7 comments · Fixed by #1700
Assignees

Comments

@vsajip
Copy link

vsajip commented Dec 23, 2022

Currently, clicking on a Tree node label both selects the node and toggles its expansion state. It would be useful if node expansion was restricted (or restrictable on a per-Tree basis) to clicks on the expansion handle (triangle), and node selection to the label only.

@Textualize Textualize deleted a comment from github-actions bot Dec 23, 2022
@willmcgugan
Copy link
Collaborator

Try auto_expand=False

@davep
Copy link
Contributor

davep commented Dec 23, 2022

Try auto_expand=False

Unfortunately that seems to stop the ability to expand a tree without the mouse (at least by default -- presumably it's possible for the developer to add their own binding). Is that by design or shall I raise an issue to this effect?

@willmcgugan
Copy link
Collaborator

If the dev doesn't want selecting the label to expand the node automatically, then they would need to expand it manually. Unless we have some "expand but don't select" binding.

@davep
Copy link
Contributor

davep commented Dec 23, 2022

Unless we have some "expand but don't select" binding.

Aye, I'm thinking it might be an idea to split action_select_cursor out a bit so the keyboard binding can always expand, but the _on_click call to action has the desired auto_expand effect? Upshot being that, with auto_expand=False, a mouse click won't expand, but a tap of Enter will, the latter being a bit more deliberate as it's the cursor keys that change selection when in keyboard mode.

At least: playing with the permutations there right now that feels right under my fingers.

@mathman1618
Copy link

Upshot being that, with auto_expand=False, a mouse click won't expand, but a tap of Enter will, the latter being a bit more deliberate as it's the cursor keys that change selection when in keyboard mode.

I'm adapting some code to the new Tree widget at present; I find auto_expand=False to work well with an additional binding (Space) for toggling node expansion. I think separating selection and expansion is preferable to having Enter both select and expand a node.

Example use case: I have a tree view tied to a hexdump. Selecting a node (single click or Enter) highlights a corresponding region in the hexdump, while clicking the triangle next to the node label or hitting Space toggles the node. In this scenario I want to be able to select a node without necessarily collapsing its portion of the tree.

(It's also possible to enable a double click to toggle a node by hacking the Driver class a bit.)

@willmcgugan
Copy link
Collaborator

Maybe fixed, or possible some other way. To investigate.

@willmcgugan willmcgugan changed the title It would be beneficial to separate Tree node selection from node toggling [Tree] It would be beneficial to separate Tree node selection from node toggling Jan 19, 2023
davep added a commit to davep/textual that referenced this issue Jan 31, 2023
See Textualize#1433. The idea here is that the user has an option of
expanding/collapsing a non-leaf node without causing a selected event,
or (with auto_expand turned off) cause a selected event without an
expand/collapse event.

As this will need a new binding, I've chosen the space bar as the key to
toggle the expanded state.
davep added a commit to davep/textual that referenced this issue Jan 31, 2023
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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 a pull request may close this issue.

4 participants