mirror of https://github.com/dbcli/pgcli
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:
parent
a713b5d08b
commit
f25e49555a
|
@ -1,7 +1,7 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/ambv/black
|
- repo: https://github.com/psf/black
|
||||||
rev: stable
|
rev: stable
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
language_version: python3.6
|
language_version: python3.7
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ def pgcli_bindings(pgcli):
|
||||||
(accept current selection).
|
(accept current selection).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
_logger.debug("Detected enter key.")
|
_logger.debug("Detected enter key during completion selection.")
|
||||||
|
|
||||||
event.current_buffer.complete_state = None
|
event.current_buffer.complete_state = None
|
||||||
event.app.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
|
# history search, and one of several conditions are True
|
||||||
@kb.add(
|
@kb.add(
|
||||||
"enter",
|
"enter",
|
||||||
filter=~(has_completions | is_searching) & buffer_should_be_handled(pgcli),
|
filter=~(completion_is_selected | is_searching)
|
||||||
|
& buffer_should_be_handled(pgcli),
|
||||||
)
|
)
|
||||||
def _(event):
|
def _(event):
|
||||||
|
_logger.debug("Detected enter key.")
|
||||||
event.current_buffer.validate_and_handle()
|
event.current_buffer.validate_and_handle()
|
||||||
|
|
||||||
@kb.add("escape", "enter")
|
@kb.add("escape", "enter")
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import logging
|
||||||
|
|
||||||
from prompt_toolkit.enums import DEFAULT_BUFFER
|
from prompt_toolkit.enums import DEFAULT_BUFFER
|
||||||
from prompt_toolkit.filters import Condition
|
from prompt_toolkit.filters import Condition
|
||||||
from prompt_toolkit.application import get_app
|
from prompt_toolkit.application import get_app
|
||||||
from .packages.parseutils.utils import is_open_quote
|
from .packages.parseutils.utils import is_open_quote
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _is_complete(sql):
|
def _is_complete(sql):
|
||||||
# A complete command is an sql statement that ends with a semicolon, unless
|
# A complete command is an sql statement that ends with a semicolon, unless
|
||||||
|
@ -24,9 +27,11 @@ def buffer_should_be_handled(pgcli):
|
||||||
@Condition
|
@Condition
|
||||||
def cond():
|
def cond():
|
||||||
if not pgcli.multi_line:
|
if not pgcli.multi_line:
|
||||||
|
_logger.debug("Not in multi-line mode. Handle the buffer.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if pgcli.multiline_mode == "safe":
|
if pgcli.multiline_mode == "safe":
|
||||||
|
_logger.debug("Multi-line mode is set to 'safe'. Do NOT handle the buffer.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
|
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
|
||||||
|
|
Loading…
Reference in New Issue