Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the condition for <enter> key. #1114

Merged
merged 2 commits into from
Oct 23, 2019
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/ambv/black
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.6
language_version: python3.7

6 changes: 4 additions & 2 deletions pgcli/key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _(event):
(accept current selection).

"""
_logger.debug("Detected enter key.")
_logger.debug("Detected enter key during completion selection.")

event.current_buffer.complete_state = None
event.app.current_buffer.complete_state = None
Expand All @@ -102,9 +102,11 @@ def _(event):
# history search, and one of several conditions are True
@kb.add(
"enter",
filter=~(has_completions | is_searching) & buffer_should_be_handled(pgcli),
filter=~(completion_is_selected | is_searching)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall using has_completions rather than completion_is_selected in #1109 consciously, but I don't remember why. Can you give an example key-press sequence to show where the existing behaviour causes issues? I use multi-line and vim mode, so it's quite possible that I didn't fully test the emacs/single-line mode - apologies for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried to add a feature test for keypress handling in #1109, but ran into issues (I was having trouble sending the correct keypress sequences as I recall).

It'd be nice if we could add some tests in this area, as I think it's important to preserve a consistent UI. Do you know if anyone has tried before - or whether it's even possible to test the key press handling such as this in a feature test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproducible key sequence:

Ensure multiline mode is OFF either via the config file or by toggling it via F3 key.

SELECT a

When you type SELECT a it will pop up a completion menu with possible suggestions for the letter a. If you press enter it should submit the command to the server but instead a newline is inserted with the completion menu kept open.

This PR fixes that situation.

& buffer_should_be_handled(pgcli),
)
def _(event):
_logger.debug("Detected enter key.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the same debug line a few lines above - should we make the output distinct (maybe add "- handling buffer" or similar)?

event.current_buffer.validate_and_handle()

@kb.add("escape", "enter")
Expand Down
5 changes: 5 additions & 0 deletions pgcli/pgbuffer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import unicode_literals
import logging

from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import Condition
from prompt_toolkit.application import get_app
from .packages.parseutils.utils import is_open_quote

_logger = logging.getLogger(__name__)


def _is_complete(sql):
# A complete command is an sql statement that ends with a semicolon, unless
Expand All @@ -24,9 +27,11 @@ def buffer_should_be_handled(pgcli):
@Condition
def cond():
if not pgcli.multi_line:
_logger.debug("Not in multi-line mode. Handle the buffer.")
return True

if pgcli.multiline_mode == "safe":
_logger.debug("Multi-line mode is set to 'safe'. Do NOT handle the buffer.")
return False

doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
Expand Down