---
epic: 5
story: 5.6
title: "Autocomplete"
status: draft
---

## Epic 5 — Variables, Line References & Aggregators
**Goal:** Transform the notepad into a lightweight computational document.

### Story 5.6: Autocomplete

As a **CalcPad user**,
I want an autocomplete popup that suggests variables, units, and functions as I type,
So that I can work faster and avoid typos in long variable names or function calls.

**Acceptance Criteria:**

**Given** the user has declared variables `monthly_rent`, `monthly_insurance`, and `mortgage_payment`
**When** the user types `mo` in the editor (2+ characters)
**Then** an autocomplete popup appears showing `monthly_rent`, `monthly_insurance`, `mortgage_payment` as suggestions

**Given** the autocomplete popup is visible with suggestions
**When** the user presses Tab or Enter
**Then** the currently highlighted suggestion is inserted into the editor at the cursor position
**And** the popup dismisses

**Given** the autocomplete popup is visible
**When** the user presses Escape
**Then** the popup dismisses without inserting anything
**And** the user's partially typed text remains unchanged

**Given** the user types `sq` in the editor
**When** the autocomplete popup appears
**Then** it includes built-in functions like `sqrt` and any user-defined variables starting with `sq`

**Given** the user types a single character (e.g., `m`)
**When** the engine checks whether to show autocomplete
**Then** the popup does NOT appear (threshold is 2+ characters)

**Given** the autocomplete popup is showing and the user continues typing
**When** the typed text no longer matches any known variable, unit, or function
**Then** the popup automatically dismisses

**Given** the user types `k` after a number (e.g., `50k`)
**When** the engine checks autocomplete context
**Then** the autocomplete recognizes this as a unit/suffix context and suggests `kg`, `km`, `kB`, etc. (not variable names)

**Given** the user navigates the autocomplete list with arrow keys
**When** the user presses Up or Down
**Then** the highlighted suggestion changes accordingly
**And** the list scrolls if necessary to keep the selection visible
