Skip to content

Commit 7b185fc

Browse files
Fix exit confirmation.
Before, the exit confirmation was not focused. Which meant that key bindings of the main buffer were still active. If we are in Vi mode, that meant that there was a key binding for the ("y", "y") already, which caused the handling of "y" to be delayed (it was not marked as eager). This fix will focus the exit confirmation and avoid further interference of buffer key bindings.
1 parent 594f0e6 commit 7b185fc

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

ptpython/key_bindings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ def _(event):
187187
Override Control-D exit, to ask for confirmation.
188188
"""
189189
if python_input.confirm_exit:
190+
# Show exit confirmation and focus it (focusing is important for
191+
# making sure the default buffer key bindings are not active).
190192
python_input.show_exit_confirmation = True
193+
python_input.app.layout.focus(
194+
python_input.ptpython_layout.exit_confirmation
195+
)
191196
else:
192197
event.app.exit(exception=EOFError)
193198

@@ -279,6 +284,7 @@ def _(event):
279284
Cancel exit.
280285
"""
281286
python_input.show_exit_confirmation = False
287+
python_input.app.layout.focus_previous()
282288

283289
return bindings
284290

ptpython/layout.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def get_text_fragments() -> StyleAndTextTuples:
501501
)
502502

503503

504-
def exit_confirmation(
504+
def create_exit_confirmation(
505505
python_input: "PythonInput", style="class:exit-confirmation"
506506
) -> Container:
507507
"""
@@ -511,7 +511,7 @@ def exit_confirmation(
511511
def get_text_fragments() -> StyleAndTextTuples:
512512
# Show "Do you really want to exit?"
513513
return [
514-
(style, "\n %s ([y]/n)" % python_input.exit_message),
514+
(style, "\n %s ([y]/n) " % python_input.exit_message),
515515
("[SetCursorPosition]", ""),
516516
(style, " \n"),
517517
]
@@ -520,8 +520,8 @@ def get_text_fragments() -> StyleAndTextTuples:
520520

521521
return ConditionalContainer(
522522
content=Window(
523-
FormattedTextControl(get_text_fragments), style=style
524-
), # , has_focus=visible)),
523+
FormattedTextControl(get_text_fragments, focusable=True), style=style
524+
),
525525
filter=visible,
526526
)
527527

@@ -635,6 +635,7 @@ def menu_position():
635635
)
636636

637637
sidebar = python_sidebar(python_input)
638+
self.exit_confirmation = create_exit_confirmation(python_input)
638639

639640
root_container = HSplit(
640641
[
@@ -680,7 +681,7 @@ def menu_position():
680681
Float(
681682
left=2,
682683
bottom=1,
683-
content=exit_confirmation(python_input),
684+
content=self.exit_confirmation,
684685
),
685686
Float(
686687
bottom=0,

0 commit comments

Comments
 (0)