textual icon indicating copy to clipboard operation
textual copied to clipboard

Add index to Tree widget's add

Open davetapley opened this issue 1 year ago • 3 comments

Presently there is no way to add a new tree node except as the last node, accordingly:

Would you accept an optional indexhere? https://github.com/Textualize/textual/blob/ce962196c73b2b87c9f812f66a6f6ded3f2aaf4b/src/textual/widgets/_tree.py#L320-L327

If set it would change this from append to insert and pass index: https://github.com/Textualize/textual/blob/ce962196c73b2b87c9f812f66a6f6ded3f2aaf4b/src/textual/widgets/_tree.py#L344

davetapley avatar Jan 20 '24 00:01 davetapley

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Jan 20 '24 00:01 github-actions[bot]

Would that cover all use-cases? What if you want to insert before another item, or at the start.

The mount method has a before and after parameter. Maybe we need something similar.

willmcgugan avatar Feb 27 '24 13:02 willmcgugan

@willmcgugan it would, but the caller would be responsible for figuring out the index.

davetapley avatar Feb 28 '24 22:02 davetapley

This would be useful 👍

When adding a new node at a level of the tree that contains many siblings, it can be really jarring having it appear right at the bottom (and causing scrolling to occur).

darrenburns avatar Jul 16 '24 13:07 darrenburns

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

github-actions[bot] avatar Jul 18 '24 15:07 github-actions[bot]