Skip to content

fix: enable Vim editing in question answers - #86

Open
oribarilan wants to merge 1 commit into
mainfrom
fix/question-answer-vim
Open

oribarilan wants to merge 1 commit into
mainfrom
fix/question-answer-vim

Conversation

@oribarilan

Copy link
Copy Markdown
Owner

Summary

Custom question answers now use the shared Vim controller on OpenCode v1 and v2. Each answer starts in insert mode with a line cursor. Escape enters normal mode without closing the answer editor.

  • Keep answer modes, undo snapshots, visual ownership, registers and leader sequences separate from the main prompt.
  • Preserve native Enter, Ctrl+Enter and Tab behavior, question choices, permissions and unrelated dialogs.
  • Apply pending answer edits before the next key, so rapid edit/submit sequences cannot commit stale text. Guard queued actions against focus changes and disposal.
  • Reuse the existing pure Vim engine. The v2 adapter only opens its form gate for a focused ANSWER textarea.

Fixes #78.

Verification

Developed test-first: the initial suite had 28 failures before production changes. Review follow-ups added 12 failing cases for rapid input ordering and disabled cursor restoration before those fixes.

  • just check: lint clean, 430 tests pass, including 75 shared v1/v2 answer regressions using real OpenTUI keymap dispatch with modeled editors and host answer layers.
  • just compat-unit: 16 tests pass.
  • Cache-installed OpenCode 1.18.33: 39 checks pass, with cold and warm loading verified. One earlier cold run timed out while loading plugins; a fresh serial retry passed.
  • Cache-installed OpenCode 2.0.15: 56 checks pass, including actual root/child answer editing, exact submitted answers, a single-write x + Enter burst, and disabled cursor shape.
  • Independent local review passed after fixing its submission-ordering and cursor-restoration findings.

Remaining limits

Live question-field coverage is v2-only. V1 has shared regression coverage, source checks and installed-host smoke coverage, but the harness does not create live v1 questions.

The existing snapshot-redo and tab-offset known gaps remain unchanged. Typecheck still reports six pre-existing errors (baseline: eight); this change introduces no new diagnostics. No dependencies or package exports changed.

@oribarilan

Copy link
Copy Markdown
Owner Author

Self-review of 7101f9b

Verdict: fix the palette-ordering issue before merge. CI is green, but the following reproduction exposes a correctness bug outside the current test suite.

P1: answer keys overtake a queued command palette

src/index.ts:202-207

In an answer containing hello world, enter normal mode, then send :x followed by Enter in one terminal write. The palette callback is outside the answer's deferred-action queue, so x deletes the final d and Enter commits the edited draft before the palette opens.

This reproduces on both modeled host paths and on cache-installed OpenCode 2.0.15. Closing the palette reveals Answer: hello worl on the form confirmation screen. The form is still pending until a separate confirmation; this is an unintended draft edit/commit, not an immediate complete question submission.

Order the answer's pending palette action with its other actions, preserve the palette's exemption from focus-loss cancellation, and re-check host ownership before routing the following key. Add a coalesced palette/edit/Enter regression alongside the existing focus-change survival test.

P2: the undo-isolation test accepts a shared stack

test/question-answer.test.ts:134-154

The test deletes in main, deletes in the answer, undoes the answer, then undoes main. A shared LIFO stack returns the same snapshots in that order. Redirecting all snapshot clear/push/pop operations to the main context in a disposable copy still leaves all 75 answer tests passing.

Undo main first while the answer still has its own snapshot, then refocus and undo the same answer object. Assert both buffers throughout.

P2: the toggle-reset test replaces the editor

test/question-answer.test.ts:392-405

Calling open() after the toggles creates a fresh editor, so the test cannot detect whether the old answer context was reset. Removing the context-reset line in a second disposable copy also leaves all 75 tests passing.

Keep the same answer editor focused across disable/re-enable, seed normal mode or a pending operator, and assert that subsequent typing uses fresh insert state.

The P2 findings are test-oracle gaps, not current production bugs. No additional blocking security, packaging, clean-code or style issues were found. The small shared context module and unchanged pure engine are appropriate for this scope.

Validation remains 430 passing tests, 16 harness-unit checks, and 39 v1 / 56 v2 installed-host checks. Live v1 question editing is still a declared coverage limit. The inherited tab-offset/snapshot-redo gaps and existing typecheck errors are outside this review. No fixes were applied during this review.

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.

vimcode doesn't work in question tool prompts

1 participant