Skip to content

Commit af4e8b9

Browse files
Fix edge case with leading line ending in 'split_lines'.
1 parent 165258d commit af4e8b9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/prompt_toolkit/formatted_text/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def split_lines(
8989
parts = string.split("\n")
9090

9191
for part in parts[:-1]:
92-
if part:
93-
line.append(cast(OneStyleAndTextTuple, (style, part, *mouse_handler)))
92+
line.append(cast(OneStyleAndTextTuple, (style, part, *mouse_handler)))
9493
yield line
9594
line = []
9695

tests/test_formatted_text.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_split_lines_3():
274274
lines = list(split_lines([("class:a", "\n")]))
275275

276276
assert lines == [
277-
[],
277+
[("class:a", "")],
278278
[("class:a", "")],
279279
]
280280

@@ -284,3 +284,15 @@ def test_split_lines_3():
284284
assert lines == [
285285
[("class:a", "")],
286286
]
287+
288+
289+
def test_split_lines_4():
290+
"Edge cases: inputs starting and ending with newlines."
291+
# -1-
292+
lines = list(split_lines([("class:a", "\nline1\n")]))
293+
294+
assert lines == [
295+
[("class:a", "")],
296+
[("class:a", "line1")],
297+
[("class:a", "")],
298+
]

0 commit comments

Comments
 (0)