summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2022-09-14 15:24:11 -0700
committerGitHub <noreply@github.com>2022-09-14 15:24:11 -0700
commit2f88df95ce297f44ebff48d76de732a004f0c42d (patch)
treed8a9a23222d4cba0aff79707abc4c2c4378e846d
parent4a853e7df4a61bd54eb16de9e6239ac7bfa91505 (diff)
parent746c1c3455bb9e49acf7ce52dad9119bb39f0160 (diff)
Merge pull request #1367 from dbcli/j-bennet/1360-esc-enter-safe-multiline-mode
Esc + Enter should sumbit the query in safe multiline mode.
-rw-r--r--changelog.rst3
-rw-r--r--pgcli/key_bindings.py4
-rw-r--r--pgcli/pgbuffer.py11
3 files changed, 15 insertions, 3 deletions
diff --git a/changelog.rst b/changelog.rst
index 952583eb..43a4c043 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -7,6 +7,7 @@ Bug fixes:
* Fix exception when retrieving password from keyring ([issue 1338](https://github.com/dbcli/pgcli/issues/1338)).
* Fix using comments with special commands ([issue 1362](https://github.com/dbcli/pgcli/issues/1362)).
* Small improvements to the Windows developer experience
+* Fix submitting queries in safe multiline mode ([1360](https://github.com/dbcli/pgcli/issues/1360)).
Internal:
---------
@@ -21,7 +22,7 @@ Bug fixes:
----------
* Fix the bug with Redshift not displaying word count in status ([related issue](https://github.com/dbcli/pgcli/issues/1320)).
-* Show the error status for CSV output format.
+* Show the error status for CSV output format.
3.4.0 (2022/02/21)
diff --git a/pgcli/key_bindings.py b/pgcli/key_bindings.py
index 7dd2924f..9c016f7f 100644
--- a/pgcli/key_bindings.py
+++ b/pgcli/key_bindings.py
@@ -9,7 +9,7 @@ from prompt_toolkit.filters import (
vi_mode,
)
-from .pgbuffer import buffer_should_be_handled
+from .pgbuffer import buffer_should_be_handled, safe_multi_line_mode
_logger = logging.getLogger(__name__)
@@ -114,7 +114,7 @@ def pgcli_bindings(pgcli):
_logger.debug("Detected enter key.")
event.current_buffer.validate_and_handle()
- @kb.add("escape", "enter", filter=~vi_mode)
+ @kb.add("escape", "enter", filter=~vi_mode & ~safe_multi_line_mode(pgcli))
def _(event):
"""Introduces a line break regardless of multi-line mode or not."""
_logger.debug("Detected alt-enter key.")
diff --git a/pgcli/pgbuffer.py b/pgcli/pgbuffer.py
index 706ed25f..c236c133 100644
--- a/pgcli/pgbuffer.py
+++ b/pgcli/pgbuffer.py
@@ -22,6 +22,17 @@ mode, which by default will insert new lines on Enter.
"""
+def safe_multi_line_mode(pgcli):
+ @Condition
+ def cond():
+ _logger.debug(
+ 'Multi-line mode state: "%s" / "%s"', pgcli.multi_line, pgcli.multiline_mode
+ )
+ return pgcli.multi_line and (pgcli.multiline_mode == "safe")
+
+ return cond
+
+
def buffer_should_be_handled(pgcli):
@Condition
def cond():