Skip to content

Commit 3130904

Browse files
Carreaumeeseeksmachine
authored andcommitted
Backport PR ipython#14717: Fix autoguesstion on ptk before 3.0.49
1 parent 0e9db37 commit 3130904

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

IPython/terminal/shortcuts/auto_suggest.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,27 @@ def apply_transformation(self, ti: TransformationInput) -> Transformation:
112112
suggestions_longer_than_buffer: bool = (
113113
len(suggestions) + ti.document.cursor_position_row > ti.document.line_count
114114
)
115+
if prompt_toolkit.VERSION < (3, 0, 49):
116+
if len(suggestions) > 1 and prompt_toolkit.VERSION < (3, 0, 49):
117+
if ti.lineno == ti.document.cursor_position_row:
118+
return Transformation(
119+
fragments=ti.fragments
120+
+ [
121+
(
122+
"red",
123+
"(Cannot show multiline suggestion; requires prompt_toolkit > 3.0.49)",
124+
)
125+
]
126+
)
127+
else:
128+
return Transformation(fragments=ti.fragments)
129+
elif len(suggestions) == 1:
130+
if ti.lineno == ti.document.cursor_position_row:
131+
return Transformation(
132+
fragments=ti.fragments + [(self.style, suggestions[0])]
133+
)
134+
return Transformation(fragments=ti.fragments)
115135

116-
if len(suggestions) >= 1 and prompt_toolkit.VERSION < (3, 0, 49):
117-
if ti.lineno == ti.document.cursor_position_row:
118-
return Transformation(
119-
fragments=ti.fragments
120-
+ [
121-
(
122-
"red",
123-
"(Cannot show multiline suggestion; requires prompt_toolkit > 3.0.49)",
124-
)
125-
]
126-
)
127-
else:
128-
return Transformation(fragments=ti.fragments)
129136
if delta == 0:
130137
suggestion = suggestions[0]
131138
return Transformation(fragments=ti.fragments + [(self.style, suggestion)])

0 commit comments

Comments
 (0)