fix(tui): re-query autocomplete picker on cursor movement
moveCursor() repositioned the cursor but never called updateAutocomplete() or cancelAutocomplete(), unlike insertCharacter()/handleBackspace(). So an open autocomplete picker went stale when the cursor moved: e.g. typing `/cmd ` (argument menu open) then arrowing Left back into the command name left the argument list showing against a `/cmd` prefix, and a Tab there concatenated the stale suggestion onto the partial command name (e.g. `/swarepo`). Sync the picker at the end of moveCursor(): when a picker is open, re-query via updateAutocomplete(), which refreshes the list for the new cursor position or closes it when nothing matches. Adds a regression test in test/editor.test.ts (verified to fail without the fix). Fixes earendil-works/pi#5496.
This commit is contained in:
@@ -1742,6 +1742,18 @@ export class Editor implements Component, Focusable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep an open autocomplete picker in sync with the new cursor
|
||||
// position: cursor movement changes the text before the cursor, so a
|
||||
// picker computed for the old position is stale. Re-query so it
|
||||
// refreshes — or closes when the new position yields no suggestions —
|
||||
// mirroring insertCharacter()/handleBackspace(). Without this, arrowing
|
||||
// left from `/cmd ` back into the command name leaves the argument
|
||||
// picker showing against a `/cmd` prefix (and a Tab there would
|
||||
// concatenate the stale suggestion onto the partial command name).
|
||||
if (this.autocompleteState) {
|
||||
this.updateAutocomplete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user