Skip to content

AutocompleteOverlay ​

Category: UI

Source: autocomplete_overlay.dart

Classes ​

AcceptResult ​

Result of accepting an autocomplete suggestion.

Represents the full new buffer contents and the absolute cursor position within it. Each overlay computes its own splicing strategy and returns the result, so the router can apply it uniformly with editor.setText(result.text, cursor: result.cursor).

Constructor ​

dart
const AcceptResult(this.text, this.cursor)

Properties ​

PropertyTypeDescription
textString
cursorint

abstract AutocompleteOverlay ​

Common contract for in-input autocomplete overlays.

Three implementations live in cli/lib/src/ui/:

  • [SlashAutocomplete] — command palette triggered by /
  • [ShellAutocomplete] — tab completion triggered inside bash mode
  • [AtFileHint] — @file reference hint

The router dispatches Up/Down/Tab/Enter/Esc to whichever overlay is currently [active]. Trigger semantics (how an overlay becomes active in the first place) differ per overlay and are NOT part of this interface — each overlay keeps its own update/requestCompletions entry point.

Properties ​

PropertyTypeDescription
activebool getWhether the overlay is currently shown and intercepting input.
selectedint getIndex of the currently highlighted match.
matchCountint getNumber of matches currently displayed.
overlayHeightint getRows the overlay occupies when rendered.
matchCountint getNumber of matches currently displayed.
selectedint getIndex of the currently highlighted match.
scrollOffsetint getFirst match index visible in the render window.
overlayHeightint getRows the overlay occupies: the match count, capped at one screenful.
activebool getWhether the overlay is currently shown and intercepting input.
selectedint getIndex of the currently highlighted match.
matchCountint getNumber of matches currently displayed.
overlayHeightint getRows the overlay occupies when rendered.
matchCountint getNumber of matches currently displayed.
selectedint getIndex of the currently highlighted match.
scrollOffsetint getFirst match index visible in the render window.
overlayHeightint getRows the overlay occupies: the match count, capped at one screenful.

Methods ​

void moveUp() ​

Move selection up (wraps).

void moveDown() ​

Move selection down (wraps).

AcceptResult? accept(String buffer, int cursor) ​

Accept the current selection, given the editor's current [buffer] and absolute [cursor] position. Returns the new buffer + cursor, or null if nothing to accept.

void dismiss() ​

Hide the overlay and reset state.

List<String> render(int width) ​

Render the overlay as styled lines for the given [width].

void resetSelection() ​

Put the cursor back at the top. Call after rebuilding the match list.

void clampSelectionToMatches() ​

Keep the selection in range after the match list was rebuilt, and put the render window back at the top.

void moveUp() ​

AutocompleteSelection ​

Selection and viewport state shared by the three overlays.

They differ entirely in how they build their match list and not at all in how the user moves through it, so [moveUp], [moveDown], the scroll clamp and [overlayHeight] live here. Implementers supply [matchCount] and reset the cursor with [resetSelection] whenever the list changes.

Properties ​

PropertyTypeDescription
matchCountint getNumber of matches currently displayed.
selectedint getIndex of the currently highlighted match.
scrollOffsetint getFirst match index visible in the render window.
overlayHeightint getRows the overlay occupies: the match count, capped at one screenful.
matchCountint getNumber of matches currently displayed.
selectedint getIndex of the currently highlighted match.
scrollOffsetint getFirst match index visible in the render window.
overlayHeightint getRows the overlay occupies: the match count, capped at one screenful.

Methods ​

void resetSelection() ​

Put the cursor back at the top. Call after rebuilding the match list.

void clampSelectionToMatches() ​

Keep the selection in range after the match list was rebuilt, and put the render window back at the top.

void moveUp() ​
void moveDown() ​
void clampScroll() ​

Slide the render window so [selected] stays inside it.

Released under the MIT License.