Skip to content

Commit

Permalink
Merge pull request #5190 from Textualize/fix-focus-within
Browse files Browse the repository at this point in the history
fixed focus-within
  • Loading branch information
willmcgugan authored Oct 29, 2024
2 parents ffd780e + c8db1d6 commit ac5d571
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- Fixed broken focus-within https://github.com/Textualize/textual/pull/5190

## [0.85.1] - 2024-10-26

### Fixed
Expand Down
11 changes: 6 additions & 5 deletions src/textual/css/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from itertools import chain
from operator import itemgetter
from pathlib import Path, PurePath
from typing import Iterable, NamedTuple, Sequence, cast
from typing import Final, Iterable, NamedTuple, Sequence, cast

import rich.repr
from rich.console import Console, ConsoleOptions, RenderableType, RenderResult
Expand Down Expand Up @@ -433,13 +433,14 @@ def _check_rule(
if _check_selectors(selector_set.selectors, css_path_nodes):
yield selector_set.specificity

# pseudo classes which iterate over many nodes
# these have the potential to be slow, and shouldn't be used in a cache key
EXPENSIVE_PSEUDO_CLASSES = {
# pseudo classes which iterate over multiple nodes
# These shouldn't be used in a cache key
_EXCLUDE_PSEUDO_CLASSES_FROM_CACHE: Final[set[str]] = {
"first-of-type",
"last-of_type",
"odd",
"even",
"focus-within",
}

def apply(
Expand Down Expand Up @@ -487,7 +488,7 @@ def apply(
cache_key: tuple | None = None

if cache is not None and all_pseudo_classes.isdisjoint(
self.EXPENSIVE_PSEUDO_CLASSES
self._EXCLUDE_PSEUDO_CLASSES_FROM_CACHE
):
cache_key = (
node._parent,
Expand Down
4 changes: 2 additions & 2 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,9 +1592,9 @@ def set_class(self, add: bool, *class_names: str, update: bool = True) -> Self:
Self.
"""
if add:
self.add_class(*class_names, update=update)
self.add_class(*class_names, update=update and self.is_attached)
else:
self.remove_class(*class_names, update=update)
self.remove_class(*class_names, update=update and self.is_attached)
return self

def set_classes(self, classes: str | Iterable[str]) -> Self:
Expand Down
5 changes: 4 additions & 1 deletion src/textual/message_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ def app(self) -> "App[object]":
@property
def is_attached(self) -> bool:
"""Is this node linked to the app through the DOM?"""
if self.app._exit:
try:
if self.app._exit:
return False
except NoActiveAppError:
return False
node: MessagePump | None = self
while (node := node._parent) is not None:
Expand Down

0 comments on commit ac5d571

Please sign in to comment.