Skip to content

feat: add inline previews for selected completions - #1051

Open
Victor-Loos wants to merge 2 commits into
HalFrgrd:masterfrom
Victor-Loos:cycle-insert
Open

Victor-Loos wants to merge 2 commits into
HalFrgrd:masterfrom
Victor-Loos:cycle-insert

Conversation

@Victor-Loos

Copy link
Copy Markdown

Add an opt-in tabCompletionCycleInsert action that writes the selected candidate into the command buffer and replaces it on subsequent Tab presses. Expose tabCompletionInserted so Enter can submit a candidate already present in the buffer.

Scope insertion requests to the active completion and invalidate them on edits, cursor movement or selection changes. Preserve the selected candidate as more results arrive or the grid changes shape, and use the complete inserted span when accepting one or all candidates.

Document the bindings and add unit and Bash PTY regression coverage for cycling, navigation, cancellation, editing, Unicode, undo and resizing.

Validation:

  • cargo test --workspace --lib --locked
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-features --locked -- -D warnings
  • cargo doc --workspace --no-deps --document-private-items --locked
  • cargo build --release --locked
  • python3 tests/tab_cycle_pty.py --flyline target/release/libflyline.so

@Kruziikrel13

Copy link
Copy Markdown
Contributor

Little video of what it looks like?

@Victor-Loos

Copy link
Copy Markdown
Author

Here’s a quick demo. Pressing Tab now puts the selected completion directly into the command line. Press Tab again to cycle through the other matches, then Enter to run the command. This behavior is opt-in through key bindings.

flyline-tab-demo.mp4

@HalFrgrd

HalFrgrd commented Nov 7, 2026

Copy link
Copy Markdown
Owner

This is a cool idea and thanks for the demo. Ive tried out your branch and I think it would make more sense to implement this feature like so:

  • I think it would make more sense to show the suggestion we have selected as a preview in italics.
  • Instead of opting via key bindings, lets make it the default when we select a suggestion from the suggestion menu.
  • Let's make it configurable via flyline --preview

Add an opt-in tabCompletionCycleInsert action that writes the selected
candidate into the command buffer and replaces it on subsequent Tab
presses. Expose tabCompletionInserted so Enter can submit a candidate
already present in the buffer.

Scope insertion requests to the active completion and invalidate them on
edits, cursor movement or selection changes. Preserve the selected
candidate as more results arrive or the grid changes shape, and use the
complete inserted span when accepting one or all candidates.

Document the bindings and add unit and Bash PTY regression coverage for
cycling, navigation, cancellation, editing, Unicode, undo and resizing.

Validation:
- cargo test --workspace --lib --locked
- cargo fmt --all -- --check
- cargo clippy --workspace --all-features --locked -- -D warnings
- cargo doc --workspace --no-deps --document-private-items --locked
- cargo build --release --locked
- python3 tests/tab_cycle_pty.py --flyline target/release/libflyline.so
Replace opt-in cycle insertion with a default display-only completion preview,
configurable with --preview. Emphasize matched input and share one mapping for
cursor placement and mouse positions without editing the buffer during preview.

Accept and submit the selected completion with one Enter press when previews
are enabled. Disabling previews restores two-step Enter: accept, then submit.
Keep Right/End acceptance aligned with the visible candidate and prevent hidden
history suggestions from taking precedence. Preserve shared-prefix expansion and
unique-match acceptance.

Map Unicode case expansions back to original input and candidate coordinates.
Traverse the ordered display mappings once during rendering.

Cover Unicode, quotes, escaped filename spaces, mouse clicks, cancellation,
selection stability and resizing. Document basic usage in the completion section.

Validation: 1089 library tests passed (1 ignored), 28 Bash PTY scenarios passed,
formatting and Clippy passed, release build and documentation completed.
Documentation retains existing rustdoc warnings.
@Victor-Loos Victor-Loos changed the title feat: add in-place tab completion cycling feat: add inline previews for selected completions Nov 19, 2026
@Victor-Loos

Copy link
Copy Markdown
Author

The selected completion now appears as an italic inline preview by default, configurable with flyline --preview / flyline --preview false.

Behavior and implementation:

  • Preview navigation does not edit the command buffer or add undo entries. It replaces the completion's word visually, including in the middle of a command and for fuzzy matches.
  • Characters matching the input are emphasized. One shared mapping handles emphasis, cursor placement and mouse positions, including Unicode case expansions, quotes and escaped filenames. The renderer traverses the ordered mappings once rather than rescanning them for every grapheme.
  • Tab, Shift+Tab, arrow navigation and mouse selection update the preview. Selection stays on the same candidate when more results arrive or the menu is resized.
  • With previews enabled, Enter accepts the selected completion and submits the command in one press. With previews disabled, Enter only accepts it; a second Enter submits the command. Incomplete commands still continue on a new line. With the cursor at the end of the input and a single-column menu, Right/End accepts the visible completion without running it.
  • Hidden history suggestions cannot take precedence through the default acceptance shortcuts while a selected completion is previewed. Disabling previews restores the original inline suggestions and two-step Enter behavior.
  • Shared-prefix expansion and unique-match acceptance are preserved. This replaces the original opt-in tabCompletionCycleInsert action and tabCompletionInserted context, so the custom bindings from the demo are no longer needed.

The rendering logic is isolated in src/app/completion_preview.rs. The existing completion-acceptance implementation is retained, and Enter chains the existing accept and submit actions only when a selected completion is previewed.

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.

3 participants