Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/prompt_toolkit/completion/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def from_nested_dict(cls, data: NestedDict) -> NestedCompleter:
elif isinstance(value, dict):
options[key] = cls.from_nested_dict(value)
elif isinstance(value, set):
options[key] = cls.from_nested_dict({item: None for item in value})
options[key] = cls.from_nested_dict(dict.fromkeys(value))
else:
assert value is None
options[key] = None
Expand Down
3 changes: 1 addition & 2 deletions src/prompt_toolkit/formatted_text/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def split_lines(
parts = string.split("\n")

for part in parts[:-1]:
if part:
line.append(cast(OneStyleAndTextTuple, (style, part, *mouse_handler)))
line.append(cast(OneStyleAndTextTuple, (style, part, *mouse_handler)))
yield line
line = []

Expand Down
14 changes: 13 additions & 1 deletion tests/test_formatted_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_split_lines_3():
lines = list(split_lines([("class:a", "\n")]))

assert lines == [
[],
[("class:a", "")],
[("class:a", "")],
]

Expand All @@ -284,3 +284,15 @@ def test_split_lines_3():
assert lines == [
[("class:a", "")],
]


def test_split_lines_4():
"Edge cases: inputs starting and ending with newlines."
# -1-
lines = list(split_lines([("class:a", "\nline1\n")]))

assert lines == [
[("class:a", "")],
[("class:a", "line1")],
[("class:a", "")],
]