diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-07 09:38:57 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-07 09:39:08 +0000 |
commit | f0ae12072ba1868526f2ae57615538777d9538f4 (patch) | |
tree | f639c1078fc22f434d074470d7b50f58f0ac6e4e /mycli/key_bindings.py | |
parent | Releasing debian version 1.25.0-1. (diff) | |
download | mycli-f0ae12072ba1868526f2ae57615538777d9538f4.tar.xz mycli-f0ae12072ba1868526f2ae57615538777d9538f4.zip |
Merging upstream version 1.26.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mycli/key_bindings.py')
-rw-r--r-- | mycli/key_bindings.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/mycli/key_bindings.py b/mycli/key_bindings.py index 4a24c82..03e4ace 100644 --- a/mycli/key_bindings.py +++ b/mycli/key_bindings.py @@ -1,6 +1,6 @@ import logging from prompt_toolkit.enums import EditingMode -from prompt_toolkit.filters import completion_is_selected +from prompt_toolkit.filters import completion_is_selected, emacs_mode, vi_mode from prompt_toolkit.key_binding import KeyBindings _logger = logging.getLogger(__name__) @@ -61,6 +61,48 @@ def mycli_bindings(mycli): else: b.start_completion(select_first=False) + @kb.add('>', filter=vi_mode) + @kb.add('c-x', 'p', filter=emacs_mode) + def _(event): + """ + Prettify and indent current statement, usually into multiple lines. + + Only accepts buffers containing single SQL statements. + """ + _logger.debug('Detected <C-x p>/> key.') + + b = event.app.current_buffer + cursorpos_relative = b.cursor_position / len(b.text) + pretty_text = mycli.handle_prettify_binding(b.text) + if len(pretty_text) > 0: + b.text = pretty_text + cursorpos_abs = int(round(cursorpos_relative * len(b.text))) + while 0 < cursorpos_abs < len(b.text) \ + and b.text[cursorpos_abs] in (' ', '\n'): + cursorpos_abs -= 1 + b.cursor_position = min(cursorpos_abs, len(b.text)) + + @kb.add('<', filter=vi_mode) + @kb.add('c-x', 'u', filter=emacs_mode) + def _(event): + """ + Unprettify and dedent current statement, usually into one line. + + Only accepts buffers containing single SQL statements. + """ + _logger.debug('Detected <C-x u>/< key.') + + b = event.app.current_buffer + cursorpos_relative = b.cursor_position / len(b.text) + unpretty_text = mycli.handle_unprettify_binding(b.text) + if len(unpretty_text) > 0: + b.text = unpretty_text + cursorpos_abs = int(round(cursorpos_relative * len(b.text))) + while 0 < cursorpos_abs < len(b.text) \ + and b.text[cursorpos_abs] in (' ', '\n'): + cursorpos_abs -= 1 + b.cursor_position = min(cursorpos_abs, len(b.text)) + @kb.add('enter', filter=completion_is_selected) def _(event): """Makes the enter key work as the tab key only when showing the menu. |