diff --git a/pyproject.toml b/pyproject.toml index 925f517d..a25b15b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "pydantic-settings==2.3.4", "python-dotenv==1.0.1", "textual-autocomplete>=3.0.0a9", - "textual[syntax]==0.72.0", + "textual[syntax]==0.73.0", ] readme = "README.md" requires-python = ">= 3.11" diff --git a/requirements-dev.lock b/requirements-dev.lock index d474d86d..3477ef44 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -79,7 +79,7 @@ rich==13.7.1 sniffio==1.3.1 # via anyio # via httpx -textual==0.72.0 +textual==0.73.0 # via posting # via textual-autocomplete # via textual-dev diff --git a/requirements.lock b/requirements.lock index b556f71d..0ed8870f 100644 --- a/requirements.lock +++ b/requirements.lock @@ -63,7 +63,7 @@ rich==13.7.1 sniffio==1.3.1 # via anyio # via httpx -textual==0.72.0 +textual==0.73.0 # via posting # via textual-autocomplete textual-autocomplete==3.0.0a9 diff --git a/src/posting/app.py b/src/posting/app.py index d0b2a21f..7f571218 100644 --- a/src/posting/app.py +++ b/src/posting/app.py @@ -103,6 +103,7 @@ class AppBody(Vertical): class MainScreen(Screen[None]): + AUTO_FOCUS = None BINDINGS = [ Binding("ctrl+j", "send_request", "Send"), Binding("ctrl+t", "change_method", "Method"), @@ -583,11 +584,6 @@ def __init__( class Posting(PostingApp): - # TODO - working around a Textual bug where the command palette - # doesnt auto focus the input by itself. When that bug is fixed, - # the AUTO_FOCUS setting should be set to None!! - # https://github.com/Textualize/textual/pull/4763 - AUTO_FOCUS = "CommandInput" COMMANDS = {PostingProvider} CSS_PATH = Path(__file__).parent / "posting.scss" BINDINGS = [ @@ -830,9 +826,6 @@ def watch__jumping(self, jumping: bool) -> None: focused_before = self.focused if focused_before is not None: self.set_focus(None, scroll_visible=False) - # TODO - the call below is working around a Textual bug - # that is fixed in https://github.com/Textualize/textual/pull/4771 - self.screen._update_focus_styles(None, blurred=focused_before) def handle_jump_target(target: str | Widget | None) -> None: if isinstance(target, str): diff --git a/src/posting/jump_overlay.py b/src/posting/jump_overlay.py index edbfce5f..e82d2bf6 100644 --- a/src/posting/jump_overlay.py +++ b/src/posting/jump_overlay.py @@ -17,7 +17,6 @@ class JumpOverlay(ModalScreen[str | Widget | None]): or a reference to the widget. Is dismissed with None if the user dismissed the overlay without making a selection.""" - AUTO_FOCUS = None DEFAULT_CSS = """\ JumpOverlay { background: black 25%; diff --git a/src/posting/widgets/collection/browser.py b/src/posting/widgets/collection/browser.py index bc363ef1..e54f21f3 100644 --- a/src/posting/widgets/collection/browser.py +++ b/src/posting/widgets/collection/browser.py @@ -271,7 +271,12 @@ def _handle_new_request_data(new_request_data: NewRequestData | None) -> None: # Attach to the relevant node new_node = self.add_request( - new_request, parent_node if pointer is self.root else pointer + new_request, + parent_node if pointer is self.root else pointer, + after=None if parent_node == cursor_node else cursor_node, + before=0 + if parent_node == cursor_node and len(parent_node.children) > 0 + else None, ) self.currently_open = new_node @@ -286,6 +291,7 @@ def _handle_new_request_data(new_request_data: NewRequestData | None) -> None: ) def post_new_request() -> None: + self.screen.set_focus(focused_before) self.select_node(new_node) self.scroll_to_node(new_node, animate=False) @@ -307,11 +313,17 @@ def post_new_request() -> None: ) def add_request( - self, request: RequestModel, parent_node: TreeNode[CollectionNode] + self, + request: RequestModel, + parent_node: TreeNode[CollectionNode], + after: TreeNode[CollectionNode] | int | None = None, + before: TreeNode[CollectionNode] | int | None = None, ) -> TreeNode[CollectionNode]: """Add a new request to the tree, and cache data from it.""" self.cache_request(request) - return parent_node.add_leaf(request.name, data=request) + return parent_node.add_leaf( + request.name, data=request, after=after, before=before + ) def cache_request(self, request: RequestModel) -> None: def get_base_url(url: str) -> str | None: diff --git a/src/posting/widgets/text_area.py b/src/posting/widgets/text_area.py index 8be1aec5..0aeefc1d 100644 --- a/src/posting/widgets/text_area.py +++ b/src/posting/widgets/text_area.py @@ -464,8 +464,9 @@ def action_cursor_bottom(self) -> None: def action_cursor_to_matched_bracket(self) -> None: # If we're already on a bracket which has a match, just jump to it and return. - if self._matching_bracket_location: - self.selection = Selection.cursor(self._matching_bracket_location) + matching_bracket_location = self.matching_bracket_location + if matching_bracket_location: + self.selection = Selection.cursor(matching_bracket_location) return # Look for a bracket on the rest of the cursor line.