Skip to content

add ic_enable_space_completes: optionally accept the selected completion with a space - #46

Open
DrStoune wants to merge 1 commit into
daanx:mainfrom
DrStoune:space-completes
Open

add ic_enable_space_completes: optionally accept the selected completion with a space#46
DrStoune wants to merge 1 commit into
daanx:mainfrom
DrStoune:space-completes

Conversation

@DrStoune

Copy link
Copy Markdown

add ic_enable_space_completes: optionally accept the selected completion with a space

Problem

In the completion menu, when an entry is selected (and shown as a preview),
typing a printable character accepts the selection and keeps typing — the
!code_is_virt_key(c) branch in edit_completion_menu. A space, however, is
classified as a virtual key (code_is_virt_key is KEY_NO_MODS(c) <= 0x20,
and space is 0x20), so it falls through to the default branch instead: the
menu closes, the selection is silently discarded, and a plain space is
inserted.

Since the preview shows the completion as if it were already inserted, having
it vanish on space is surprising — space is the most common "accept this word
and keep typing" key on a command line. zsh's menuselect and the fish pager
both accept the selected entry on space.

Change

A new opt-in toggle, following the existing ic_enable_* pattern:

/// Enable or disable that a space accepts the selected completion in the
/// completion menu and is inserted after it, like the zsh menu selection
/// or the fish pager (disabled by default).
/// Returns the previous setting.
bool ic_enable_space_completes( bool enable );

Default is off, so behavior is unchanged unless the application asks for
it. When enabled, a space with an entry selected accepts the entry and then
inserts the space after it (the space is pushed back like any other passthrough
key). The new branch mirrors the selected >= 0 guard of the enter/right/end
branch, so it behaves consistently in both preview and no-preview modes.

23 added lines, no lines removed: one flag in ic_env_t, one branch in
edit_completion_menu, the setter, the doc comment, and a readme row.

Testing

  • gcc -Wall -Wextra -c src/isocline.c — no new warnings vs. main (27 before,
    27 after).
  • pty-driven check (test program + driver attached in the PR branch comments):
    completer offering apple / banana / cherry, key sequence
    TAB TAB SPACE X ENTER:
    • toggle off (default): LINE=[ X] — selection discarded, identical to main
    • toggle on: LINE=[apple X] — selection accepted, space inserted after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant