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
8 changes: 6 additions & 2 deletions src/toad/client/line_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,18 @@ def selection_text(self) -> str:
return self.label


class TextLineBlock(LineBlock):
"""A line block whose selectable text is its own ``text``."""
class TextSelectionSource:
"""Exposes its own ``text`` as selectable text."""

@property
def selection_text(self) -> str:
return self.text


class TextLineBlock(TextSelectionSource, LineBlock):
"""A line block whose selectable text is its own ``text``."""


@dataclass(frozen=True)
class SpanText(TextLineBlock):
"""Text made of spans; subclasses decide whether it wraps or clips."""
Expand Down
15 changes: 8 additions & 7 deletions src/toad/rich_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
from textual.visual import RenderOptions
from textual.text_format import TextFormat, TextFormatSnapshot
from toad.colour_ink import ColourInk
from toad.client.line_blocks import LineBlock, LineRole, ToolOutputRole, MutedRole
from toad.client.line_blocks import (
LineBlock,
LineRole,
MutedRole,
TextSelectionSource,
ToolOutputRole,
)

if TYPE_CHECKING:
from textual.app import App
Expand Down Expand Up @@ -259,7 +265,7 @@ def selected_text(self, selection: Selection, prepared: PreparedRichContent) ->


@dataclass(frozen=True)
class PreparedRichContent:
class PreparedRichContent(TextSelectionSource):
width: int
lines: tuple[Strip, ...]

Expand All @@ -271,11 +277,6 @@ def retained_bytes(self) -> int:
def text(self) -> str:
return "\n".join(line.text for line in self.lines)

@property
def selection_text(self) -> str:
"""Rich previews select their prepared terminal rows."""
return self.text

def render_lines(self, crop: Region, *, selection=None, selection_style=None) -> list[Strip]:
"""Crop original prepared rows without rebuilding a native subtree."""
result = []
Expand Down
32 changes: 18 additions & 14 deletions src/toad/widgets/path_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,21 @@ def search(self) -> PathSearch:
return self.query_ancestor(PathSearch)

@property
@abstractmethod
def toggled(self) -> PickerPane:
"""The pane Tab switches to."""
return self.search.query_one(self._toggled_step())

@abstractmethod
def _toggled_step(self):
...

@property
def cursor_owner(self) -> MovesCursor:
return self.query_one(self._cursor_owner_step())

@abstractmethod
def cursor_owner(self) -> MovesCursor: ...
def _cursor_owner_step(self):
...

@property
@abstractmethod
Expand All @@ -180,13 +188,11 @@ async def suggest_node(self, node: TreeNode[DirEntry]) -> None:
class FuzzyPane(PickerPane):
"""Fuzzy search over the project's paths."""

@property
def toggled(self) -> PickerPane:
return self.search.query_one(TreePane)
def _toggled_step(self):
return TreePane

@property
def cursor_owner(self) -> FuzzyPathOptionList:
return self.query_one(FuzzyPathOptionList)
def _cursor_owner_step(self):
return FuzzyPathOptionList

@property
def focus_target(self) -> FuzzyInput:
Expand All @@ -211,13 +217,11 @@ class TreePane(PickerPane):
def mount_lock(self) -> asyncio.Lock:
return asyncio.Lock()

@property
def toggled(self) -> PickerPane:
return self.search.query_one(FuzzyPane)
def _toggled_step(self):
return FuzzyPane

@property
def cursor_owner(self) -> ProjectDirectoryTree:
return self.query_one(ProjectDirectoryTree)
def _cursor_owner_step(self):
return ProjectDirectoryTree

@property
def focus_target(self) -> ProjectDirectoryTree:
Expand Down
6 changes: 2 additions & 4 deletions src/toad/widgets/session_thread_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def sidebar_thread_identity(self):
return next((references.thread(thread).read(SidebarThreadIdentity(screen.wire_root))
for thread in self.threads), NoThreadIdentity())

def make_panels(self):
screen = self._owner()
def _make_panels_step(self, screen):
if screen is None:
raise ReferenceError("The conversation sidebar owner has retired")
return (member().compose_panel(screen) for thread in self.threads
Expand Down Expand Up @@ -128,8 +127,7 @@ def capture_panels(self, screen: MainScreen) -> None:
owner.capture(panel.widget)
screen._project_panel = NO_PROJECT_VIEW

def make_panels(self):
screen = self._owner()
def _make_panels_step(self, screen):
if screen is None:
raise ReferenceError("The session sidebar owner has retired")
return (owner.compose_panel(screen) for owner in self._panel_owners)
7 changes: 6 additions & 1 deletion src/toad/widgets/side_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,8 +1435,13 @@ def __init__(self, *panels, **kwargs):
def wants_panels(self) -> bool:
return super().wants_panels and not self.collapsed

def make_panels(self):
screen = self._owner()
return self._make_panels_step(screen)

@abstractmethod
def make_panels(self): ...
def _make_panels_step(self, screen):
...

def _compose_panels(self):
if not self.panels:
Expand Down
Loading