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():