1
0
Fork 0

Fix the condition for <enter> key. (#1114)

* Fix the condition for <enter> key.

* Improve the debug message and remove debug statement.
This commit is contained in:
Amjith Ramanujam 2019-10-23 14:11:44 -07:00 committed by Owen Stephens
parent a713b5d08b
commit f25e49555a
3 changed files with 11 additions and 4 deletions

View File

@ -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

View File

@ -92,7 +92,7 @@ def pgcli_bindings(pgcli):
(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
@ -102,9 +102,11 @@ def pgcli_bindings(pgcli):
# 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)
& buffer_should_be_handled(pgcli),
)
def _(event):
_logger.debug("Detected enter key.")
event.current_buffer.validate_and_handle()
@kb.add("escape", "enter")

View File

@ -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
@ -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