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

Add index to Tree widget's add #4049

Closed
davetapley opened this issue Jan 20, 2024 · 5 comments · Fixed by #4772
Closed

Add index to Tree widget's add #4049

davetapley opened this issue Jan 20, 2024 · 5 comments · Fixed by #4772

Comments

@davetapley
Copy link
Contributor

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

Would you accept an optional indexhere?

def add(
self,
label: TextType,
data: TreeDataType | None = None,
*,
expand: bool = False,
allow_expand: bool = True,
) -> TreeNode[TreeDataType]:

If set it would change this from append to insert and pass index:

self._children.append(node)

Copy link

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

@willmcgugan
Copy link
Collaborator

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.

@davetapley
Copy link
Contributor Author

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

@darrenburns
Copy link
Member

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).

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.

3 participants