Harden completion popup selection bounds

This commit is contained in:
Bill
2026-02-16 18:10:35 -07:00
parent 2d4c29d403
commit 90560be614
2 changed files with 19 additions and 0 deletions

View File

@@ -455,6 +455,7 @@ static void renderEditorPanel(EditorState& state) {
bool popupHovered =
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
int maxIndex = std::max(0, (int)filtered.size() - 1);
state.completionSelected = std::max(0, std::min(state.completionSelected, maxIndex));
if (ImGui::IsKeyPressed(ImGuiKey_DownArrow)) {
state.completionSelected = std::min(state.completionSelected + 1, maxIndex);
}
@@ -500,6 +501,9 @@ static void renderEditorPanel(EditorState& state) {
}
if (accept && !filtered.empty()) {
state.completionSelected =
std::max(0, std::min(state.completionSelected,
(int)filtered.size() - 1));
const auto& item = filtered[state.completionSelected];
bool preferred = built.preferredNames.count(item.label) > 0;
if (!preferred) {

View File

@@ -5303,6 +5303,21 @@ dismiss, especially noticeable in text-mode editing.
- `editor/src/EditorState.h` remains within header-size limit (`634` > `600`) — existing oversize file prior to this hotfix
- `editor/src/panels/EditorPanel.h` remains within header-size limit (`850` > `600`) — existing oversize file prior to this hotfix
### Hotfix D: completion selection bounds hardening (stability)
**Status:** PASS (build stable)
Hardened completion popup selection handling to prevent stale-selection indexing
when the candidate list shrinks between frames (e.g., while typing quickly and
confirming with Enter/Tab).
**Files modified:**
- `editor/src/panels/EditorPanel.h` — clamped `completionSelected` before navigation and before selection accept
**Verification run:**
- `cmake --build editor/build-native --target whetstone_editor` — PASS
- `step54_test` — PASS (10/10) regression coverage
- `step437_test` — PASS (8/8) regression coverage
# Roadmap Planning — Sprints 12-25+
## Status: Planning Complete (Sprints 12-19 detailed, 20-25 in roadmap.md)