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/pad/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ class TextSearchModal(ModalScreen[None]):

CSS = """
TextSearchModal {
align: center middle;
align: center bottom;
background: transparent;
}

#text-search-container {
Expand All @@ -297,6 +298,7 @@ class TextSearchModal(ModalScreen[None]):
background: $surface;
border: tall $primary;
padding: 1 2;
margin-bottom: 1; /* prevents gutter overlap */
}

#text-search-input {
Expand Down Expand Up @@ -654,7 +656,8 @@ class GoToLineModal(ModalScreen[int | None]):

CSS = """
GoToLineModal {
align: center middle;
align: center bottom;
background: transparent;
}

#goto-container {
Expand All @@ -664,6 +667,7 @@ class GoToLineModal(ModalScreen[int | None]):
background: $surface;
border: tall $primary;
padding: 1 2;
margin-bottom: 1; /* prevents gutter overlap */
}

#goto-label {
Expand Down
41 changes: 39 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
from pathlib import Path

from textual.app import App
from textual.screen import ModalScreen

from rich.markup import MarkupError

from pad.app import ContentSearchModal
from pad.app import ContentSearchModal, GoToLineModal, TextSearchModal


class _TestApp(App):
"""Minimal app to host a modal for testing."""

def __init__(self, modal: ContentSearchModal) -> None:
def __init__(self, modal: ModalScreen[object]) -> None:
super().__init__()
self._modal = modal

Expand Down Expand Up @@ -111,3 +112,39 @@ async def run_test() -> None:
assert modal.results[0][0] == text_file

asyncio.run(run_test())


def test_text_search_modal_renders_at_bottom() -> None:
"""Text search modal should be docked to the bottom of the screen."""
modal = TextSearchModal("sample text", lambda _position: None)

async def run_test() -> None:
app = _TestApp(modal)
async with app.run_test(size=(100, 40)) as pilot:
await pilot.pause()

container = modal.query_one("#text-search-container")
screen_bottom = app.screen.region.bottom

assert modal.styles.align == ("center", "bottom")
assert screen_bottom - container.region.bottom == 1

asyncio.run(run_test())


def test_goto_line_modal_renders_at_bottom() -> None:
"""Go-to-line modal should be docked to the bottom of the screen."""
modal = GoToLineModal(200)

async def run_test() -> None:
app = _TestApp(modal)
async with app.run_test(size=(100, 40)) as pilot:
await pilot.pause()

container = modal.query_one("#goto-container")
screen_bottom = app.screen.region.bottom

assert modal.styles.align == ("center", "bottom")
assert screen_bottom - container.region.bottom == 1

asyncio.run(run_test())