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

Fix missing Tree.NodeHighlighted message #3528

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

robinvd
Copy link

@robinvd robinvd commented Oct 13, 2023

When the tree has no selection the cursor_line is -1, then clicking on the last node in the tree will check if the selection is different from the last selection, and do a check nodes[previous_cursor_line] != nodes[new_cursor_line] but if previous_cursor_line=-1 and new_cursor_line=len(nodes)-1 then this will fail and the message will not be emitted.

Please review the following checklist.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

Robin added 2 commits October 13, 2023 11:56
When the tree has no selection the cursor_line is -1, then clicking
on the last node in the tree will check if the selection is different
from the last selection, and do a check nodes[previous_cursor_line] !=
nodes[new_cursor_line] but if previous_cursor_line=-1 and
new_cursor_line=len(nodes)-1 then this will fail and the message will
not be emitted.
@TomJGooding
Copy link
Contributor

Any chance of a regression test? I'm not a maintainer of Textual, but I'm sure you'll be asked this when someone gets to reviewing this. Thanks for you PR!

@robinvd
Copy link
Author

robinvd commented Oct 31, 2023

any change to review this @davep (or other maintainers)

@davep
Copy link
Collaborator

davep commented Oct 31, 2023

@robinvd We've got a lot going on so sometimes it can take us a wee while to get through PRs. Meanwhile though what Tom said is good advice: if you've identified a bug and this is a PR to fix it then a regression test would be very welcome.

@robinvd
Copy link
Author

robinvd commented Oct 31, 2023 via email

@davep
Copy link
Collaborator

davep commented Oct 31, 2023

Just to add too: having enabled the running of tests in CI: it looks like your change might be causing some existing tests to fail; you will want to take that into account.

@willmcgugan
Copy link
Collaborator

@robinvd Could you open an issue for this please. With a small example that reproduces the problem. Just to help me understand what this is fixing.

@willmcgugan
Copy link
Collaborator

Closing. Assumed stale.

@robinvd
Copy link
Author

robinvd commented Apr 2, 2024

@willmcgugan repro example

from textual.app import App
from textual.widgets import Tree


class BugApp(App):
    def compose(self):
        t = Tree("test")
        t.show_root = False
        t.root.add_leaf("node1")
        t.root.add_leaf("node2")
        t.root.add_leaf("node3")
        yield t

    def on_tree_node_highlighted(self, event):
        self.notify(f"hightlight! {event}")


BugApp().run()

if you now click on the last node, no notification will popup

@willmcgugan willmcgugan reopened this Apr 2, 2024
Copy link
Contributor

@TomJGooding TomJGooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong but this looks like an issue only when show_root=False is set in compose?

Currently this PR causes multiple existing tests to fail as @davep already mentioned. I wonder perhaps this just needs a check if show_root is False.

src/textual/widgets/_tree.py Outdated Show resolved Hide resolved
robinvd and others added 2 commits April 3, 2024 09:08
Co-authored-by: TomJGooding <101601846+TomJGooding@users.noreply.github.com>
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 this pull request may close these issues.

None yet

4 participants