Fix various small things
A commit that fixes all of the little things I forgot about, but that are necessary for rendering to function properly. - (attr. lines) reverse lines before extending above - (attr. lines) clamp the AttributedLine offset so that there is always a line with offset 0 - (tree renderer) use meta spaces for the cursor too - (tree renderer) use correct indent text for cursor - (tree renderer) fix mypy error by safely ignoring it - (supply) sort by root id instead of value - (supply) return id, not list of ids
This commit is contained in:
parent
5a606a9191
commit
5e10fcecac
3 changed files with 10 additions and 6 deletions
|
|
@ -75,7 +75,7 @@ class AttributedLines:
|
||||||
AttributedLines's offsets instead.
|
AttributedLines's offsets instead.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._lines.extendleft(lines._lines)
|
self._lines.extendleft(reversed(lines._lines))
|
||||||
self.upper_offset -= len(lines)
|
self.upper_offset -= len(lines)
|
||||||
|
|
||||||
def extend_below(self, lines: "AttributedLines") -> None:
|
def extend_below(self, lines: "AttributedLines") -> None:
|
||||||
|
|
@ -105,6 +105,7 @@ class AttributedLines:
|
||||||
|
|
||||||
attr_lines = AttributedLines(lines)
|
attr_lines = AttributedLines(lines)
|
||||||
attr_lines.upper_offset = max(start_offset, self.upper_offset)
|
attr_lines.upper_offset = max(start_offset, self.upper_offset)
|
||||||
|
attr_lines.lower_offset = min(end_offset, self.lower_offset)
|
||||||
return attr_lines
|
return attr_lines
|
||||||
|
|
||||||
def to_size(self, start_offset: int, end_offset: int) -> "AttributedLines":
|
def to_size(self, start_offset: int, end_offset: int) -> "AttributedLines":
|
||||||
|
|
|
||||||
|
|
@ -156,8 +156,10 @@ class CursorTreeRenderer(Generic[E]):
|
||||||
) -> AttributedLines:
|
) -> AttributedLines:
|
||||||
lines = AttributedLines()
|
lines = AttributedLines()
|
||||||
width = self._width - len(indent) - self._renderer.meta_width
|
width = self._width - len(indent) - self._renderer.meta_width
|
||||||
|
meta_spaces = AT(" " * self._renderer.meta_width)
|
||||||
attrs = {"cursor": True, "offset": 0}
|
attrs = {"cursor": True, "offset": 0}
|
||||||
lines.append_below(attrs, self._renderer.render_cursor(width))
|
lines.append_below(attrs, meta_spaces + indent +
|
||||||
|
self._renderer.render_cursor(width))
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def _render_indent(self,
|
def _render_indent(self,
|
||||||
|
|
@ -217,7 +219,7 @@ class CursorTreeRenderer(Generic[E]):
|
||||||
lines.lower_offset = -1
|
lines.lower_offset = -1
|
||||||
|
|
||||||
cursor_indent = indent + self._render_indent(cursor_line=True)
|
cursor_indent = indent + self._render_indent(cursor_line=True)
|
||||||
lines.extend_below(self._render_cursor(indent))
|
lines.extend_below(self._render_cursor(cursor_indent))
|
||||||
|
|
||||||
def _render_tree(self, root_id: Id) -> AttributedLines:
|
def _render_tree(self, root_id: Id) -> AttributedLines:
|
||||||
lines = AttributedLines()
|
lines = AttributedLines()
|
||||||
|
|
@ -350,8 +352,9 @@ class CursorTreeRenderer(Generic[E]):
|
||||||
if self._cursor_id is None and self._anchor_id is None:
|
if self._cursor_id is None and self._anchor_id is None:
|
||||||
return self._render_lines_from_cursor()
|
return self._render_lines_from_cursor()
|
||||||
|
|
||||||
|
working_id: Id
|
||||||
if self._anchor_id is None:
|
if self._anchor_id is None:
|
||||||
working_id = self._cursor_id
|
working_id = self._cursor_id # type: ignore
|
||||||
else:
|
else:
|
||||||
working_id = self._anchor_id
|
working_id = self._anchor_id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ class InMemorySupply(ElementSupply[E]):
|
||||||
return elem.parent_id
|
return elem.parent_id
|
||||||
|
|
||||||
def _roots(self) -> List[Id]:
|
def _roots(self) -> List[Id]:
|
||||||
roots = (m for m in self._elements.values() if m.parent_id is None)
|
roots = (i for i, m in self._elements.items() if m.parent_id is None)
|
||||||
return list(sorted(roots))
|
return list(sorted(roots))
|
||||||
|
|
||||||
def sibling_ids(self, elem_id: Id) -> List[Id]:
|
def sibling_ids(self, elem_id: Id) -> List[Id]:
|
||||||
|
|
@ -189,6 +189,6 @@ class InMemorySupply(ElementSupply[E]):
|
||||||
roots = self._roots()
|
roots = self._roots()
|
||||||
|
|
||||||
if roots:
|
if roots:
|
||||||
return roots[:-1]
|
return roots[-1]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue