Skip to content

fix(tui): re-query autocomplete picker on cursor movement#5499

Merged
badlogic merged 1 commit into
earendil-works:mainfrom
Roman-Galeev:fix/editor-cursor-move-refresh-autocomplete
Jun 8, 2026
Merged

fix(tui): re-query autocomplete picker on cursor movement#5499
badlogic merged 1 commit into
earendil-works:mainfrom
Roman-Galeev:fix/editor-cursor-move-refresh-autocomplete

Conversation

@Roman-Galeev

Copy link
Copy Markdown
Contributor

Fixes #5496.

Problem

Editor.moveCursor() repositions the cursor but never calls updateAutocomplete() or cancelAutocomplete() — unlike insertCharacter() and handleBackspace(), which both keep the picker in sync. So an open autocomplete picker goes stale when the cursor moves.

Repro (with a slash command whose first argument is a sub-command, e.g. repo | message | help):

  1. Type /cmd (trailing space) → the argument picker opens.
  2. Press Left to move back into the command name; the text before the cursor is now /cmd.
  3. The picker still shows the arguments. Pressing Tab there lands in applyCompletion's file-path branch (no space before the cursor) and concatenates the stale value onto the partial command name, e.g. /cmd + repo/cmdrepo.

Fix

At the end of moveCursor(), when a picker is open, call updateAutocomplete() — which re-queries for the new cursor position (refreshing the list, or closing it via runAutocompleteRequest when nothing matches). This mirrors the existing insertCharacter() / handleBackspace() behaviour. moveCursor() is only reached from the arrow-key dispatch sites, so the refresh does not fire during delete operations.

Test

Adds a regression test in packages/tui/test/editor.test.ts (re-queries the autocomplete picker when the cursor moves back into the command name): types /cmd , arrows Left, and asserts the stale argument items are gone from the rendered picker. Verified it fails without the fix and passes with it. Full node --test test/*.test.ts is green (642 tests).

Scope

This addresses the reported arrow-key path (moveCursor). As noted in #5496, other cursor-only movements (Home/End, word jumps, page scroll) share the same gap and could be extended the same way — kept out of this PR to stay focused, happy to broaden if preferred.

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#5496.
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues daily. Issues that do not meet the quality bar in CONTRIBUTING.md will not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this Jun 8, 2026
@badlogic badlogic reopened this Jun 8, 2026
@badlogic badlogic merged commit 21917fe into earendil-works:main Jun 8, 2026
2 checks passed
@badlogic

badlogic commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: cursor movement (arrow keys) leaves a stale autocomplete picker

2 participants