Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Sep 25, 2024
1 parent 3096f8b commit a4249b5
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 318 deletions.
3 changes: 3 additions & 0 deletions src/textual/widgets/_directory_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,6 @@ def _on_tree_node_selected(self, event: Tree.NodeSelected[DirEntry]) -> None:
self.post_message(self.DirectorySelected(event.node, dir_entry.path))
else:
self.post_message(self.FileSelected(event.node, dir_entry.path))

def _on_mount(self):
self.move_cursor_to_line(0)
9 changes: 9 additions & 0 deletions src/textual/widgets/_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,15 @@ def move_cursor(
animate=animate and abs(self.cursor_line - previous_cursor_line) > 1,
)

def move_cursor_to_line(self, line: int, animate=False) -> None:
if line < 0:
line = len(self._tree_lines) + line
try:
node = self._tree_lines[line].node
except IndexError:
raise IndexError("No line no. {line} in the tree")
self.move_cursor(node, animate=animate)

def select_node(self, node: TreeNode[TreeDataType] | None) -> None:
"""Move the cursor to the given node and select it, or reset cursor.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a4249b5

Please sign in to comment.