-
Notifications
You must be signed in to change notification settings - Fork 814
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 links in markup changes state of all links with identical action / parameter #1587
Comments
Hey @mitosch, just want to let you know that I'm working on a fix for this and I have narrowed down the cause of the issue after banging my head against the wall for a moderate amount of time. |
@willmcgugan I'll probably block this issue until there's some clarity on a path forward via resolution of Textualize/rich#2949. Or do you think I should try to work around rich#2949 to fix this symptom in Textual? |
I don't think this is a Rich issue per se, but is clearly related to |
So far, I've been able to determine that disabling the caches in |
Working on Textualize/textual#1587 surfaced a caching issue that is best shown by running the code below: ```py from rich.style import Style meta = {"click": "something"} s1 = Style.from_meta(meta) s2 = Style.from_meta(meta) print(s1.link_id, s2.link_id) # Different link_id. base = Style(color="red") print((base + s1).link_id) # This is the link_id of s1. print((base + s2).link_id) # This is the link_id of s1! ``` The change presented here will bypass cache when adding styles that have a link id but don't have a link attribute (if they did, so would the combined style and the call to .copy would refresh the link id either way). Simply refreshing the link id will break Textual link highlighting.
Opened a draft PR with a solution. The reasoning and my findings are included in the PR and also included verbatim under the toggle below. Reasoning & findingsThe issue we're dealing with boils down to the fact that the attribute
We can't, because we don't want equality comparison to depend on When working on #1587, the first fix I found was that I could disable the cache inside from rich.style import Style
meta = {"click": "something"}
s1 = Style.from_meta(meta)
s2 = Style.from_meta(meta)
print(s1.link_id, s2.link_id) # Different link_id.
# (
# '6311506187629892456089155',
# '4273756187629892456089155'
# )
base = Style(color="red")
print((base + s1).link_id) # This is the link_id of s1.
# '6311506187629892456089155'
# Now, we add base to s2:
# vv
print((base + s2).link_id) # This is the link_id of s1!
# '6311506187629892456089155' Now, we can take a look at how addition is implemented and this reveals a promising workaround: class Style:
# ...
def __add__(self, style: Optional["Style"]) -> "Style":
combined_style = self._add(style)
return combined_style.copy() if combined_style.link else combined_style The call to return combined_style.copy() if combined_style.link or combined_style.meta else combined_style However, this breaks link highlighting on the Textual side entirely – as in, no link gets any highlighting – because Textual relies on the link IDs to know what to highlight. A potential fix is to bypass the cache entirely when adding styles that have link IDs but no links. |
Issue Description
Hovering one link will change the hover state of all links having the same action/params.
Given the example below, the links 1, 3 and 4 are changing the state together:
Further analysis:
Working Example
The text was updated successfully, but these errors were encountered: