Fix drawing of non-top-level anchors

This commit is contained in:
Joscha 2019-05-12 10:59:38 +00:00
parent 6fae53e0c8
commit 0c5369cd9d
2 changed files with 26 additions and 32 deletions

View file

@ -69,14 +69,6 @@ class ElementSupply(abc.ABC):
return children
# There is not a clear-cut way to get the previous or next "sibling" of an
# element that is itself a child of the implicit root (None), since
# get_children() doesn't accept None in its element_id argument.
#
# Because of this, the get_previous_id() and get_next_id() functions are
# abstract (until I decide to change the signature of get_children(), that
# is :P).
def get_previous_id(self, element_id: Id) -> Optional[Id]:
"""
Get the id of an element's previous sibling (i. e. the sibling just
@ -139,28 +131,29 @@ class ElementSupply(abc.ABC):
else:
return None
# def get_furthest_ancestor_id(self,
# element_id: Id,
# root_id: Optional[Id] = None,
# ) -> Id:
# current_id = element_id
#
# while True:
# parent_id = self.get_parent_id(current_id)
#
# if parent_id == root_id:
# return current_id
# elif parent_id is None:
# raise TreeException("Reached implicit root before hitting specified root")
#
# current_id = parent_id
#
# def get_furthest_ancestor(self,
# element_id: Id,
# root_id: Optional[Id] = None,
# ) -> Element:
# return self.get(self.get_furthest_ancestor_id(element_id,
# root_id=root_id))
def get_furthest_ancestor_id(self,
element_id: Id,
root_id: Optional[Id] = None,
) -> Id:
current_id = element_id
while True:
parent_id = self.get_parent_id(current_id)
if parent_id == root_id:
return current_id
elif parent_id is None:
raise TreeException(
"Reached implicit root before hitting specified root")
current_id = parent_id
def get_furthest_ancestor(self,
element_id: Id,
root_id: Optional[Id] = None,
) -> Element:
return self.get(self.get_furthest_ancestor_id(element_id,
root_id=root_id))
class MemoryElementSupply(ElementSupply):
"""

View file

@ -195,9 +195,10 @@ class TreeDisplay:
self._rendered = None
return
anchor_tree = self._render_tree(self.anchor_id)
ancestor_id = self._supply.get_furthest_ancestor_id(self.anchor_id)
ancestor_tree = self._render_tree(ancestor_id)
self._rendered = TreeList(anchor_tree, self.anchor_id)
self._rendered = TreeList(ancestor_tree, self.anchor_id)
self._rendered.offset_by(self.anchor_offset)
self._fill_screen_upwards()