Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/textual/css/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import ClassVar, Protocol, Self, overload

from metaclass_registry.descendants import Descendants
from metaclass_registry.own_declarations import OwnDeclarations

from textual.css._declaration import NativeProperty, ValueBuilder
from textual.css._style_properties import StyleProperty
Expand Down Expand Up @@ -132,7 +133,7 @@ def named(css_name: str) -> "Component | None":
if part.css_name == css_name), None)


class DeclaresTheme:
class DeclaresTheme(OwnDeclarations):
"""Owns native theme declarations: each class declares its own, the MRO composes them."""

native_theme: ClassVar[tuple[NativeDeclaration, ...]] = ()
Expand All @@ -141,11 +142,7 @@ class DeclaresTheme:
@cache
def declared_theme(cls) -> tuple[NativeDeclaration, ...]:
"""Every class's own declarations, base first, so the most derived wins."""
return tuple(
declaration
for owner in reversed(cls.__mro__)
for declaration in vars(owner).get("native_theme", ())
)
return tuple(cls.declared_items("native_theme", reversed(cls.__mro__)))


class ThemedNode(Protocol):
Expand Down
16 changes: 0 additions & 16 deletions src/textual/document/_editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,6 @@ def paste(self, editor: TextArea, text: str) -> None:
editor.move_cursor(result.end_location)


class NativeTextKeys:
"""A control whose printable keys are text, whatever its screen's keyboard profile."""

@property
def takes_typed_text(self) -> bool:
return True

@property
def key_mode(self) -> type[EditingMode]:
return EditingMode

@property
def allows_application_commands(self) -> bool:
return self.key_mode().allows_application_commands


class VimMode(EditingMode, ModalInputMode, ABC):
"""Modal binding capability, not a second implementation of Vim."""

Expand Down
17 changes: 5 additions & 12 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@
from rich.text import Text
from rich.tree import Tree

from formbridge.key_declarations import KeymapClaim
from formbridge.key_declarations import KeymapClaim, TextEntryMode
from formbridge.navigation_commands import NavigationCommand
from metaclass_registry.descendants import Descendants
from metaclass_registry.own_declarations import OwnDeclarations
from formbridge.key_declarations import TextEntryMode
from textual._context import active_message_pump
from textual._compat import cached_property
from textual._node_list import NodeList
from textual._paint_state import PaintNode
from textual._types import WatchCallbackType
from textual.binding import Binding, BindingsMap, BindingType, CommandBinding, MethodBinding, ModeBinding
from textual.document._editing import EditingMode
from textual.cache import LRUCache
from textual.css._error_tools import friendly_list
from textual.css.constants import VALID_DISPLAY, VALID_VISIBILITY
Expand Down Expand Up @@ -148,7 +146,7 @@ class DOMNode(DeclaresTheme, PaintNode, MessagePump, OwnDeclarations, Descendant
_geometry_revision = 0

@property
def key_mode(self) -> type[EditingMode]:
def key_mode(self) -> type[TextEntryMode]:
"""Ordinary controls use their screen's declared keyboard scope."""
return self.screen.key_mode

Expand Down Expand Up @@ -1137,12 +1135,7 @@ def _merge_bindings(cls) -> BindingsMap:
@lru_cache(maxsize=None)
def theme_states(cls) -> tuple[ThemeState, ...]:
"""Every look this class's state selects, in MRO order."""
return tuple(
state
for owner in reversed(cls.__mro__)
for state in vars(owner).values()
if isinstance(state, ThemeState)
)
return tuple(cls.declared_of(ThemeState, reversed(cls.__mro__)))

def native_declarations(self) -> tuple[NativeDeclaration, ...]:
"""The class's own declarations, then each current look's; providers may extend it."""
Expand All @@ -1168,8 +1161,8 @@ def apply_native_layout(self) -> None:
def declared_components(cls) -> Mapping[Component, tuple[NativeDeclaration, ...]]:
"""Every class's own component declarations, base first, so the most derived wins."""
declared: dict[Component, tuple[NativeDeclaration, ...]] = {}
for owner in reversed(cls.__mro__):
for part, declarations in vars(owner).get("native_components", {}).items():
for _, components in cls.own_declarations("native_components", reversed(cls.__mro__)):
for part, declarations in components.items():
declared[part] = (*declared.get(part, ()), *declarations)
return declared

Expand Down
2 changes: 1 addition & 1 deletion src/textual/widgets/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from textual.binding import Binding, BindingType, MethodBinding
from textual.css._error_tools import friendly_list
from textual.css.native import Component
from textual.document._editing import NativeTextKeys
from formbridge.key_declarations import NativeTextKeys
from textual.events import Blur, Focus, Mount
from textual.geometry import Offset, Region, Size, clamp
from textual.cursor_shape import CursorShape, TextEntryCursor
Expand Down