Autocomplete: scroll the highlighted item into view on arrow nav
#7 in Riparion/riparion-editor — merged 2026-06-02
Problem
The [[/ smart-tag dropdown scrolls (max-height:18rem; overflow-y:auto), but arrow-key navigation only moved the highlight class — it never scrolled the menu. Once the highlight passed the bottom visible edge, the selection walked off-screen and the items below the fold were unreachable. With 8 items and only ~4 visible, ↓ couldn't reach the last four.
Fix
In CompletionPopup (src/autocomplete.rs):
- Each rendered row reports its DOM element via
onmountedinto aSignal<HashMap<String, Rc<MountedData>>>, keyed byitem.label(the same value rows arekeyed on). Label-keying — not index — stays correct when the filter narrows, since a surviving row keeps its DOM node and never re-firesonmounted. - A
use_effect(use_reactive!(|(selected, labels)| …))watches theselectedprop and callsel.scroll_to(ScrollBehavior::Instant)to pull the highlighted row into view.use_reactive!becauseselectedis a plain prop (a bareuse_effectwouldn't re-run on prop change);InstantbecauseSmoothlags behind held arrow keys.
Testing
Expanded the markdown example's smart-tag catalog from 3 to 13 entries so the menu overflows and the scroll is exercisable.
dx serve --example markdown --features web
Type [[/ in a block, hold ↓ — the list now scrolls and reaches the final entries.
cargo clippy --features web --example markdown and cargo test (20 passing) both clean.
🤖 Generated with Claude Code
Last updated 2026-06-03
Links to this note
Merged pull requests, newest first.