Skip to content

Commit c3424b0

Browse files
authored
CHop fix (#2227)
1 parent 976bd2f commit c3424b0

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/textual/_compositor.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
from __future__ import annotations
1515

1616
from operator import itemgetter
17-
from typing import TYPE_CHECKING, Callable, Iterable, NamedTuple, cast
17+
from typing import (
18+
TYPE_CHECKING,
19+
Callable,
20+
Iterable,
21+
Mapping,
22+
NamedTuple,
23+
Sequence,
24+
cast,
25+
)
1826

1927
import rich.repr
2028
from rich.console import Console, ConsoleOptions, RenderableType, RenderResult
@@ -105,7 +113,7 @@ class ChopsUpdate:
105113

106114
def __init__(
107115
self,
108-
chops: list[dict[int, Strip | None]],
116+
chops: Sequence[Mapping[int, Strip | None]],
109117
spans: list[tuple[int, int, int]],
110118
chop_ends: list[list[int]],
111119
) -> None:
@@ -876,7 +884,7 @@ def _render_chops(
876884
self,
877885
crop: Region,
878886
is_rendered_line: Callable[[int], bool],
879-
) -> list[dict[int, Strip | None]]:
887+
) -> Sequence[Mapping[int, Strip | None]]:
880888
"""Render update 'chops'.
881889
882890
Args:
@@ -907,10 +915,8 @@ def _render_chops(
907915
chops_line = chops[y]
908916

909917
first_cut, last_cut = render_region.column_span
910-
cuts_line = cuts[y]
911-
final_cuts = [
912-
cut for cut in cuts_line if (last_cut >= cut >= first_cut)
913-
]
918+
final_cuts = [cut for cut in cuts[y] if (last_cut >= cut >= first_cut)]
919+
914920
if len(final_cuts) <= 2:
915921
# Two cuts, which means the entire line
916922
cut_strips = [strip]
@@ -920,8 +926,9 @@ def _render_chops(
920926
cut_strips = strip.divide(relative_cuts)
921927

922928
# Since we are painting front to back, the first segments for a cut "wins"
929+
get_chops_line = chops_line.get
923930
for cut, strip in zip(final_cuts, cut_strips):
924-
if chops_line[cut] is None:
931+
if get_chops_line(cut) is None:
925932
chops_line[cut] = strip
926933

927934
return chops

src/textual/strip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from itertools import chain
4-
from typing import Iterable, Iterator
4+
from typing import Iterable, Iterator, Sequence
55

66
import rich.repr
77
from rich.cells import cell_len, set_cell_size
@@ -348,7 +348,7 @@ def crop(self, start: int, end: int) -> Strip:
348348
self._crop_cache[cache_key] = strip
349349
return strip
350350

351-
def divide(self, cuts: Iterable[int]) -> list[Strip]:
351+
def divide(self, cuts: Iterable[int]) -> Sequence[Strip]:
352352
"""Divide the strip in to multiple smaller strips by cutting at given (cell) indices.
353353
354354
Args:

0 commit comments

Comments
 (0)