Skip to content

Commit a26c6f5

Browse files
committed
Fix typechecking
1 parent 2339c02 commit a26c6f5

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/prompt_toolkit/layout/containers.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ def render_margin(m: Margin, width: int) -> UIContent:
19441944
def _whitespace_wrap_finder(
19451945
self,
19461946
ui_content: UIContent,
1947-
sep: str | re.Pattern = r"\s",
1947+
sep: str | re.Pattern[str] = r"\s",
19481948
split: str = "remove",
19491949
continuation: StyleAndTextTuples = [],
19501950
) -> WrapFinderCallable:
@@ -2024,15 +2024,22 @@ def _copy_body(
20242024
# Maps (row, col) from the input to (y, x) screen coordinates.
20252025
rowcol_to_yx: dict[tuple[int, int], tuple[int, int]] = {}
20262026

2027-
def find_next_wrap(remaining_width, is_input, lineno, fragment=0, char_pos=0):
2027+
def find_next_wrap(
2028+
remaining_width: int,
2029+
is_input: bool,
2030+
lineno: int,
2031+
fragment: int = 0,
2032+
char_pos: int = 0,
2033+
) -> tuple[int, int, AnyFormattedText]:
20282034
if not wrap_lines:
20292035
return sys.maxsize, 0, []
20302036

20312037
line = ui_content.get_line(lineno)
20322038
style0, text0, *more = line[fragment]
2033-
char_pos - fragment_list_len(line[:fragment])
2034-
line_part = [(style0, text0[char_pos:], *more), *line[fragment + 1 :]]
2035-
line_width = [fragment_list_width([fragment]) for fragment in line_part]
2039+
char_pos -= fragment_list_len(line[:fragment])
2040+
line_part = [(style0, text0[char_pos:]), *line[fragment + 1 :]]
2041+
line_width = [fragment_list_width([frag]) for frag in line_part]
2042+
line_width = [fragment_list_width([frag]) for frag in line_part]
20362043

20372044
if sum(line_width) <= remaining_width:
20382045
return sys.maxsize, 0, []
@@ -2054,10 +2061,15 @@ def find_next_wrap(remaining_width, is_input, lineno, fragment=0, char_pos=0):
20542061
remaining_width -= char_width
20552062
max_wrap_pos += 1
20562063

2057-
if is_input and wrap_finder:
2058-
return wrap_finder(lineno, min_wrap_pos, max_wrap_pos)
2059-
else:
2060-
return max_wrap_pos, 0, []
2064+
return (
2065+
wrap_finder(lineno, min_wrap_pos, max_wrap_pos)
2066+
if is_input and wrap_finder
2067+
else None
2068+
) or (
2069+
max_wrap_pos,
2070+
0,
2071+
[],
2072+
)
20612073

20622074
def copy_line(
20632075
line: StyleAndTextTuples,

src/prompt_toolkit/layout/menus.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from prompt_toolkit.utils import get_cwidth
2828

2929
from .containers import ConditionalContainer, HSplit, ScrollOffsets, Window
30-
from .controls import GetLinePrefixCallable, UIContent, UIControl
30+
from .controls import GetLinePrefixCallable, UIContent, UIControl, WrapFinderCallable
3131
from .dimension import Dimension
3232
from .margins import ScrollbarMargin
3333

@@ -80,6 +80,7 @@ def preferred_height(
8080
max_available_height: int,
8181
wrap_lines: bool,
8282
get_line_prefix: GetLinePrefixCallable | None,
83+
wrap_finder: WrapFinderCallable | None,
8384
) -> int | None:
8485
complete_state = get_app().current_buffer.complete_state
8586
if complete_state:
@@ -378,6 +379,7 @@ def preferred_height(
378379
max_available_height: int,
379380
wrap_lines: bool,
380381
get_line_prefix: GetLinePrefixCallable | None,
382+
wrap_finder: WrapFinderCallable | None,
381383
) -> int | None:
382384
"""
383385
Preferred height: as much as needed in order to display all the completions.
@@ -718,6 +720,7 @@ def preferred_height(
718720
max_available_height: int,
719721
wrap_lines: bool,
720722
get_line_prefix: GetLinePrefixCallable | None,
723+
wrap_finder: WrapFinderCallable | None,
721724
) -> int | None:
722725
return 1
723726

0 commit comments

Comments
 (0)