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

Hovering over an empty DataTable row does not reset hover effect #2909

Closed
ThatOtherAndrew opened this issue Jul 10, 2023 · 5 comments · Fixed by #3018
Closed

Hovering over an empty DataTable row does not reset hover effect #2909

ThatOtherAndrew opened this issue Jul 10, 2023 · 5 comments · Fixed by #3018

Comments

@ThatOtherAndrew
Copy link

Have you checked closed issues? https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed

Yes, I have.

Please give a brief but clear explanation of the issue. If you can, include a complete working example that demonstrates the bug. Check it can run without modifications.

To reproduce the issue, run the below code and hover the cursor above one of the cells. Then, move the cursor down into the empty space below, and observe how the orange highlighting on the cell persists.

from textual.app import App
from textual.widgets import DataTable

class ExampleApp(App):
    def compose(self):
        table = DataTable()
        table.add_columns('foo', 'bar', 'baz')
        table.add_row('foo', 'bar', 'baz')
        table.styles.height = '100%'
        yield table

ExampleApp().run()

It will be helpful if you run the following command and paste the results:

textual diagnose

Textual Diagnostics

Versions

Name Value
Textual 0.27.0
Rich 13.4.2

Python

Name Value
Version 3.11.3
Implementation CPython
Compiler MSC v.1934 64 bit (AMD64)
Executable C:\Users\Andrew\AppData\Local\Programs\Python\Python311\python.exe

Operating System

Name Value
System Windows
Release 10
Version 10.0.22621

Terminal

Name Value
Terminal Application Windows Terminal
TERM Not set
COLORTERM Not set
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=120, height=30
legacy_windows False
min_width 1
max_width 120
is_terminal True
encoding utf-8
max_height 30
justify None
overflow None
no_wrap False
highlight None
markup None
height None

Feel free to add screenshots and / or videos. These can be very helpful!

textual_datatable_cursor_hover.mp4
@github-actions
Copy link

We found the following entry 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

@TomJGooding
Copy link
Contributor

TomJGooding commented Jul 11, 2023

I thought this might be a quick fix, but I can't seem to unset the hover cursor similar to when focus leaves the widget.

def _on_mouse_move(self, event: events.MouseMove):
"""If the hover cursor is visible, display it by extracting the row
and column metadata from the segments present in the cells."""
self._set_hover_cursor(True)
meta = event.style.meta
if meta and self.show_cursor and self.cursor_type != "none":
try:
self.hover_coordinate = Coordinate(meta["row"], meta["column"])
except KeyError:
pass
def _on_leave(self, _: events.Leave) -> None:
self._set_hover_cursor(False)

A simple workaround would be to set the table height to auto and wrap it inside a container.

@TomJGooding
Copy link
Contributor

I've been looking at this issue again as it feels like it should be such an easy fix.

If the mouse isn't hovering a cell in the table, then there's no meta info. But I can't seem to conditionally unset the hover cursor no matter what I try, so there must be something I'm missing.

@darrenburns do you have any ideas? Sorry I normally wouldn't tag individuals, but it seems like you're the DataTable expert!

@darrenburns
Copy link
Member

I think you're looking at the correct code, but there looks like a cacheing bug too, which is preventing the update from being visible.

The cell render cache key doesn't include self._show_hover_cursor, which means subsequent repaints of the cell containing the hover cursor will get the old cached rendered cell (with hover cursor highlighting), regardless of whether self._show_hover_cursor is True or False.

Adding self._show_hover_cursor to the cell render cache_key (inside render_cell), combined with the changes you suggested above, should do the trick.

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

3 participants