textual
textual copied to clipboard
Add index to Tree widget's add
Presently there is no way to add a new tree node except as the last node, accordingly:
Would you accept an optional index
here?
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
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
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 it would, but the caller would be responsible for figuring out the index.
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).