Skip to content

Commit 75a1128

Browse files
committed
Make wrap_finder somewhat easier to reuse
1 parent 2834081 commit 75a1128

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: src/prompt_toolkit/layout/containers.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ def _write_to_screen_at_index(
17841784
ui_content, write_position.width - total_margin_width, write_position.height
17851785
)
17861786
wrap_finder = self.wrap_finder or (
1787-
self._whitespace_wrap_finder(ui_content) if self.word_wrap() else None
1787+
self._whitespace_wrap_finder(ui_content.get_line) if self.word_wrap() else None
17881788
)
17891789

17901790
# Erase background and fill with `char`.
@@ -1941,10 +1941,11 @@ def render_margin(m: Margin, width: int) -> UIContent:
19411941
# position.
19421942
screen.visible_windows_to_write_positions[self] = write_position
19431943

1944+
@classmethod
19441945
def _whitespace_wrap_finder(
1945-
self,
1946-
ui_content: UIContent,
1947-
sep: str | re.Pattern[str] = r"\s",
1946+
cls,
1947+
get_line: Callable[[int], StyleAndTextTuples],
1948+
sep: str | re.Pattern[str] = r"[ \t]", # Don’t include \xA0 by default (in \s)
19481949
split: str = "remove",
19491950
continuation: StyleAndTextTuples = [],
19501951
) -> WrapFinderCallable:
@@ -1968,7 +1969,7 @@ def _whitespace_wrap_finder(
19681969
def wrap_finder(
19691970
lineno: int, start: int, end: int
19701971
) -> tuple[int, int, AnyFormattedText]:
1971-
line = explode_text_fragments(ui_content.get_line(lineno))
1972+
line = explode_text_fragments(get_line(lineno))
19721973
cont_reserved = 0
19731974
while cont_reserved < cont_width:
19741975
style, char, *_ = line[end - 1]

0 commit comments

Comments
 (0)