Skip to content

Commit d5f08c5

Browse files
committed
feat: Make toggle auto-completion keybinding configurable
Add toggle_auto_completion_key option to pgclirc that allows users to customize the key(s) that toggle the completion menu. Supports multiple space-separated keys that each get their own independent binding. Defaults to c-space for backward compatibility.
1 parent 2936e0f commit d5f08c5

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

pgcli/key_bindings.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ def _(event):
189189
event.current_buffer.complete_state = None
190190
event.app.current_buffer.complete_state = None
191191

192-
@kb.add("c-space")
193-
def _(event):
192+
# Bind each key in toggle_completion_key to toggle completion.
193+
# Space-separated keys each get their own binding.
194+
# e.g., "c-space c-t" binds both Ctrl+Space and Ctrl+T independently.
195+
toggle_keys = pgcli.toggle_auto_completion_key.strip().split()
196+
197+
def _toggle_completion(event):
194198
"""
195199
Toggle autocompletion at cursor.
196200
@@ -199,16 +203,15 @@ def _(event):
199203
200204
If the menu is showing, close it (toggle off).
201205
"""
202-
_logger.debug("Detected <C-Space> key.")
203-
204206
b = event.app.current_buffer
205207
if b.complete_state:
206-
# Close completion menu (toggle off)
207208
b.complete_state = None
208209
else:
209-
# Open completion menu (toggle on)
210210
b.start_completion(select_first=False)
211211

212+
for _key in toggle_keys:
213+
kb.add(_key)(_toggle_completion)
214+
212215
@kb.add("c-j", filter=has_completions)
213216
def _(event):
214217
"""

pgcli/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ def __init__(
255255
self.column_date_formats = c["column_date_formats"]
256256
auth.keyring_initialize(c["main"].as_bool("keyring"), logger=self.logger)
257257
self.show_bottom_toolbar = c["main"].as_bool("show_bottom_toolbar")
258+
self.toggle_auto_completion_key = c["main"].get(
259+
"toggle_auto_completion_key", "c-space"
260+
)
258261

259262
self.pgspecial.pset_pager(self.config["main"].as_bool("enable_pager") and "on" or "off")
260263

pgcli/pgclirc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ syntax_style = default
154154
# Ctrl+k - Navigate to previous completion (up) - Vim style
155155
# Ctrl+p - Move up in history
156156
# Ctrl+n - Move down in history
157+
158+
# Key binding for toggling the auto-completion menu on/off.
159+
# Uses prompt_toolkit key notation. Space-separated keys each
160+
# get their own independent binding. Examples:
161+
# c-space (Ctrl+Space - default)
162+
# c-t (Ctrl+T)
163+
# c-space c-t (both Ctrl+Space and Ctrl+T will toggle)
164+
# See prompt_toolkit docs for full key notation reference.
165+
toggle_auto_completion_key = c-space
166+
157167
vi = False
158168

159169
# Error handling

0 commit comments

Comments
 (0)