Skip to content

Commit

Permalink
Inserting nodes into tree right below the cursor position
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jul 18, 2024
1 parent ef66109 commit 5a29981
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/posting/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 0 additions & 1 deletion src/posting/jump_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down
12 changes: 9 additions & 3 deletions src/posting/widgets/collection/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ 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,
cursor_node,
)
self.currently_open = new_node

Expand All @@ -286,6 +288,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)

Expand All @@ -307,11 +310,14 @@ def post_new_request() -> None:
)

def add_request(
self, request: RequestModel, parent_node: TreeNode[CollectionNode]
self,
request: RequestModel,
parent_node: TreeNode[CollectionNode],
cursor_node: TreeNode[CollectionNode] | 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=cursor_node)

def cache_request(self, request: RequestModel) -> None:
def get_base_url(url: str) -> str | None:
Expand Down

0 comments on commit 5a29981

Please sign in to comment.