summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Stephens <owen@owenstephens.co.uk>2019-10-16 22:26:25 +0100
committerOwen Stephens <owen@owenstephens.co.uk>2019-10-16 22:26:25 +0100
commit629a931aedd290bcf69ddcb6ac1e0fd807b5a448 (patch)
tree68249a538e3def7ae4e28b01e323d96c74cd1e64
parent6763433a687cc651d9ce5c97eeb81d83c4d34f71 (diff)
fixup! fixup! Handle a multi-line query on Enter key-press (fixes #1031)
-rw-r--r--changelog.rst1
-rw-r--r--pgcli/key_bindings.py5
-rw-r--r--pgcli/main.py8
-rw-r--r--pgcli/pgbuffer.py14
4 files changed, 17 insertions, 11 deletions
diff --git a/changelog.rst b/changelog.rst
index e33fb00b..225707c6 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -15,6 +15,7 @@ Bug fixes:
* History navigation bindings in multiline queries (#1004) (Thanks: `Pedro Ferrari`_)
* Can't connect to pgbouncer database (#1093). (Thanks: `Irina Truong`_)
* Fix broken multi-line history search (#1031). (Thanks: `Owen Stephens`_)
+* Fix slow typing/movement when multi-line query ends in a semicolon (#994). (Thanks: `Owen Stephens`_)
Internal:
---------
diff --git a/pgcli/key_bindings.py b/pgcli/key_bindings.py
index 6eb71f9f..6a4cb065 100644
--- a/pgcli/key_bindings.py
+++ b/pgcli/key_bindings.py
@@ -10,7 +10,7 @@ from prompt_toolkit.filters import (
has_selection,
)
-from .pgbuffer import multi_line_buffer_should_be_handled
+from .pgbuffer import buffer_should_be_handled
_logger = logging.getLogger(__name__)
@@ -102,8 +102,7 @@ def pgcli_bindings(pgcli):
# history search, and one of several conditions are True
@kb.add(
"enter",
- filter=~(completion_is_selected | is_searching)
- & multi_line_buffer_should_be_handled(pgcli),
+ filter=~(has_completions | is_searching) & buffer_should_be_handled(pgcli),
)
def _(event):
event.current_buffer.validate_and_handle()
diff --git a/pgcli/main.py b/pgcli/main.py
index 7d5b35bd..d5f6bd89 100644
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -35,7 +35,7 @@ from prompt_toolkit.completion import DynamicCompleter, ThreadedCompleter
from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
from prompt_toolkit.shortcuts import PromptSession, CompleteStyle
from prompt_toolkit.document import Document
-from prompt_toolkit.filters import HasFocus, IsDone, Condition
+from prompt_toolkit.filters import HasFocus, IsDone
from prompt_toolkit.lexers import PygmentsLexer
from prompt_toolkit.layout.processors import (
ConditionalProcessor,
@@ -809,7 +809,11 @@ class PGCli(object):
],
auto_suggest=AutoSuggestFromHistory(),
tempfile_suffix=".sql",
- multiline=Condition(lambda: self.multi_line),
+ # N.b. pgcli's multi-line mode controls submit-on-Enter (which
+ # overrides the default behaviour of prompt_toolkit) and is
+ # distinct from prompt_toolkit's multiline mode here, which
+ # controls layout/display of the prompt/buffer
+ multiline=True,
history=history,
completer=ThreadedCompleter(DynamicCompleter(lambda: self.completer)),
complete_while_typing=True,
diff --git a/pgcli/pgbuffer.py b/pgcli/pgbuffer.py
index 995ee208..51f9b869 100644
--- a/pgcli/pgbuffer.py
+++ b/pgcli/pgbuffer.py
@@ -14,17 +14,19 @@ def _is_complete(sql):
"""
-Returns True if the input mode is multi-line using psql mode, and the main
-buffer's contents indicate that it should be handled, False otherwise. This
-method is required since by default prompt_toolkit would not handle a buffer on
-Enter keypress when in multi-line mode.
+Returns True if the buffer contents should be handled (i.e. the query/command
+executed) immediately. This is necessary as we use prompt_toolkit in multiline
+mode, which by default will insert new lines on Enter.
"""
-def multi_line_buffer_should_be_handled(pgcli):
+def buffer_should_be_handled(pgcli):
@Condition
def cond():
- if not pgcli.multi_line or pgcli.multiline_mode == "safe":
+ if not pgcli.multi_line:
+ return True
+
+ if pgcli.multiline_mode == "safe":
return False
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document