From d6b3472db057e35e908c9a91873e94b0de2654c4 Mon Sep 17 00:00:00 2001 From: Irina Truong Date: Thu, 8 Sep 2022 15:14:42 -0700 Subject: [PATCH 1/3] Esc + Enter should sumbit the query in safe multiline mode. --- pgcli/key_bindings.py | 4 ++-- pgcli/pgbuffer.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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..6fdbfba1 100644 --- a/pgcli/pgbuffer.py +++ b/pgcli/pgbuffer.py @@ -22,6 +22,14 @@ 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(): From 73d84eea2876864871bec0b45ddf4fda461602bb Mon Sep 17 00:00:00 2001 From: Irina Truong Date: Wed, 14 Sep 2022 14:58:45 -0700 Subject: [PATCH 2/3] Black. --- pgcli/pgbuffer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pgcli/pgbuffer.py b/pgcli/pgbuffer.py index 6fdbfba1..c236c133 100644 --- a/pgcli/pgbuffer.py +++ b/pgcli/pgbuffer.py @@ -25,8 +25,11 @@ 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) + _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 From 746c1c3455bb9e49acf7ce52dad9119bb39f0160 Mon Sep 17 00:00:00 2001 From: Irina Truong Date: Wed, 14 Sep 2022 15:01:09 -0700 Subject: [PATCH 3/3] Changelog. --- changelog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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)