summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2019-03-16 14:07:39 -0700
committerGitHub <noreply@github.com>2019-03-16 14:07:39 -0700
commitb8f6974f14e9eb37023e944a943015ca932bff72 (patch)
treedcdc516de86c1a0740efb05e42712cff59daedfc
parent7d6523e18b2c752e0a404746018df77cbad5bcdb (diff)
parentcbd944ffab7206d03a675dc5384553874c2889a7 (diff)
Merge pull request #928 from arturbalabanov/tab-on-line-start
Tab press on an empty line increases the indentation instead of triggering the auto-complete pop-up
-rw-r--r--changelog.rst2
-rw-r--r--pgcli/key_bindings.py20
-rw-r--r--pgcli/pgclirc3
3 files changed, 20 insertions, 5 deletions
diff --git a/changelog.rst b/changelog.rst
index 7af82674..2a3e446f 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -42,6 +42,8 @@ Internal:
Bug fixes:
----------
+* Tab press on an empty line increases the indentation instead of triggering
+ the auto-complete pop-up. (Thanks: `Artur Balabanov`_)
* Fix for loading/saving named queries from provided config file (#938). (Thanks: `Daniel Egger`_)
* Set default port in `connect_uri` when none is given. (Thanks: `Daniel Egger`_)
* Fix for error listing databases (#951). (Thanks: `Irina Truong`_)
diff --git a/pgcli/key_bindings.py b/pgcli/key_bindings.py
index 6e2afe35..cda4fb6c 100644
--- a/pgcli/key_bindings.py
+++ b/pgcli/key_bindings.py
@@ -12,6 +12,9 @@ def pgcli_bindings(pgcli):
"""Custom key bindings for pgcli."""
kb = KeyBindings()
+ expand_tab = pgcli.config['main'].as_bool('expand_tab')
+ tab_insert_text = ' ' * 4 if expand_tab else '\t'
+
@kb.add('f2')
def _(event):
"""Enable/Disable SmartCompletion Mode."""
@@ -33,13 +36,20 @@ def pgcli_bindings(pgcli):
@kb.add('tab')
def _(event):
- """Force autocompletion at cursor."""
+ """Force autocompletion at cursor on non-empty lines."""
+
_logger.debug('Detected <Tab> key.')
- b = event.app.current_buffer
- if b.complete_state:
- b.complete_next()
+
+ buff = event.app.current_buffer
+ doc = buff.document
+
+ if doc.on_first_line or doc.current_line.strip():
+ if buff.complete_state:
+ buff.complete_next()
+ else:
+ buff.start_completion(select_first=True)
else:
- b.start_completion(select_first=True)
+ buff.insert_text(tab_insert_text, fire_event=False)
@kb.add('escape')
def _(event):
diff --git a/pgcli/pgclirc b/pgcli/pgclirc
index 78d78366..8b452506 100644
--- a/pgcli/pgclirc
+++ b/pgcli/pgclirc
@@ -143,6 +143,9 @@ enable_pager = True
# Use keyring to automatically save and load password in a secure manner
keyring = True
+# When the <Tab> key is pressed on an empty line, use 4 spaces instead of \t
+expand_tab = False
+
# Custom colors for the completion menu, toolbar, etc.
[colors]
completion-menu.completion.current = 'bg:#ffffff #000000'