Skip to content

mac editor: Tab accepts the fix at the caret (#277) - #445

Merged
GoKubar merged 1 commit into
mainfrom
quick-fix-tab-editor
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
quick-fix-tab-editor

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What

A quick fix was something you went and found in the Problems panel and clicked.
This offers it where the author is typing, and accepts it with Tab.

Tab's precedence

Tab is heavily overloaded, so the order is explicit:

  1. an input-method composition — untouched, Tab never reaches this code;
  2. a snippet placeholder (CompletingTextView.keyDown) — modal, mid-edit;
  3. the completion list (CompletingTextView.keyDown, and handleTab's own
    isCompletionActive guard) — modal, the author is looking at it;
  4. the fix at the caret — new;
  5. indent a multi-line selection;
  6. insert an indent unit at the caret.

Completion and snippets keep the key because they are modal and the author is
mid-interaction. Step 4 takes it from indentation only on three conditions, so
Tab never does something invisible:

  • a fix is actually offered and showing (Esc has not taken it down);
  • the selection is empty — a multi-line selection is unambiguously "indent this
    block", never "fix a word in it";
  • it is Tab, not ⇧Tab, which always means outdent.

With nothing offered, handleTab falls straight through and Tab indents exactly
as before. Esc takes the hint down — ahead of Esc's other meaning, opening
the completion list — and Tab indents again until the caret moves onto another
fix.

Seeing it before accepting it

With the caret on (or directly either side of) a diagnostic that carries a
mechanical edit, the fix is drawn after that line as ⇥ \alpha in the accent
colour, beside the error-lens message when one is showing.

It is drawn whatever the error-lens preference says, because Tab acts on it.
A hint the author has switched off, silently arming a key, is the bug this
feature could most easily have been — so it does not ride on an optional
affordance. ShellModel.caretFix is the single value that both draws the hint
and arms the key, so the two cannot disagree.

The hint extends the existing ErrorLensPainter rather than adding a second
painter: foregroundDecorator is a single slot, and a new painter would have
silently displaced the error lens.

One undo step

Accepting routes through previewQuickFix + applyQuickFix — the panel's own
path — rather than a second application path, so the edit ledger, the revision
counter and undo behave identically.

Why this had nothing to accept before

canApplyHelpReplacement required help.replacement. But the app attaches
flashtex-render by default (ShellModel.locateDefaultProducer prefers it over
the compiler), and display::Diagnostic has no help field — the render
pipeline builds against the pinned vendor/compiler, which has no
DiagnosticHelp type at all. Measured on that wire, a \alpah typo arrives as:

{"code":"unknown_command","message":"\\alpah is not supported...",
 "source":{"start_byte":44,"end_byte":50,"path":"main.tex"},"suggestion":"\\alpha"}
has_suggestion=true  has_help=false

Bytes 44..50 are exactly the command token. mechanicalEdit already understood
that flat form; only the gate did not, so the affordance — and the panel's
"Fix…" button with it — was unreachable in the shipping configuration. The gate
now asks mechanicalEdit, which accepts both forms. The compiler sets
suggestion at exactly one site (Diagnostic::command_error), where the span
is the command token, so this is the same edit help.replacement would carry.

caretFix bails out before caretByte — a conversion linear in the document —
unless some diagnostic actually carries an edit, because it is read on every
keystroke.

Verified

swift build clean. swift test --skip NearbyInterfaceTests --skip NearbyLANInterfaceTests on mac-m1max-a:

  • baseline (unmodified faa7d484): 1136 tests, 2 failures
  • this branch: 1151 tests (+15), 2 failures

The 2 failures are identical on both and pre-existing — CommandTableTests
asserting that ⌥⇧↓/⌥⇧↑ (#419) are documented in the README. Nothing to do
with this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

A quick fix was something you went and found in the Problems panel and
clicked. This offers it where the author is typing and accepts it with Tab.

The affordance is drawn before it can be accepted: when the caret is on a
diagnostic that carries a mechanical edit, the fix appears after that line as
`⇥ \alpha`, in the accent colour, next to the error-lens message when one is
showing. It is drawn whatever the error-lens preference says, because Tab acts
on it — a hint the author has switched off, silently arming a key, is the bug
this feature could most easily have been. `ShellModel.caretFix` is the single
value that both draws the hint and arms the key, so the two cannot disagree.

Tab's precedence, in order:
  1. an input-method composition — untouched, Tab never reaches this code;
  2. a snippet placeholder (`CompletingTextView.keyDown`) — modal, mid-edit;
  3. the completion list (`CompletingTextView.keyDown`, and `handleTab`'s own
     `isCompletionActive` guard) — modal, the author is looking at it;
  4. **the fix at the caret** — new;
  5. indent a multi-line selection;
  6. insert an indent unit at the caret.

Step 4 only takes the key on three conditions, so Tab never does something
invisible: a fix is actually offered (and Esc has not taken it down), the
selection is empty, and it is Tab rather than ⇧Tab. A multi-line selection is
unambiguously "indent this block" and keeps the key; ⇧Tab always outdents.
With nothing offered this falls straight through and Tab indents exactly as
before. Esc takes the hint down — ahead of Esc's other meaning, opening the
completion list — and Tab indents again until the caret moves onto another fix.

Accepting routes through `previewQuickFix` + `applyQuickFix`, the panel's own
path, rather than a second application path, so the edit ledger, the revision
counter and undo behave identically: one undo step.

The gate is also why this had nothing to accept before. `canApplyHelpReplacement`
required `help.replacement`, but the app attaches `flashtex-render` by default
(`ShellModel.locateDefaultProducer` prefers it over the compiler), and
`display::Diagnostic` has no `help` field — the render pipeline builds against
the pinned `vendor/compiler`, which has no `DiagnosticHelp` type at all. The
wire carries only the flat `suggestion`. Measured on that wire, a `\alpah` typo
arrives as `suggestion: "\alpha"` over `source` bytes 44..50 — exactly the
command token — and `has_help=false`. `mechanicalEdit` already understood that
form; only the gate did not, so the affordance was unreachable in the shipping
configuration. It now asks `mechanicalEdit`, which accepts both forms. The
compiler sets `suggestion` at exactly one site (`Diagnostic::command_error`),
where the span is the command token, so this is the same edit
`help.replacement` would have carried.

`caretFix` bails out before `caretByte` — a conversion linear in the document —
unless some diagnostic actually carries an edit, because it is read on every
keystroke.

Verified on mac-m1max-a: swift build clean; swift test --skip
NearbyInterfaceTests --skip NearbyLANInterfaceTests.

Implementation-Agent: Claude Opus 5 (lane quick-fix-tab, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

daniel-parent: an overlap note, nothing blocking. This PR and my #423 (code folding) both edit Completion.swift, and they test-merge with a conflict. Merge in whatever order suits you: if #445 lands first I'll rebase #423, and if #423 lands first, ping me and I'll resolve it on this branch's behalf. #445 merges cleanly with my other Mac PRs (#411, #412, #413, #425, #426, #429).

@GoKubar
GoKubar merged commit ed796d9 into main Sep 14, 2026
20 of 21 checks passed
@GoKubar
GoKubar deleted the quick-fix-tab-editor branch September 14, 2026 19:12
d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged origin/main (includes #413 Re-indent, #419 duplicate line, #442 Vim
status line, #445 caret fix). Conflict in apps/mac/README.md: kept both
the ⌘L Go to Line row (ours) and the ⌃I / Re-indent Document rows (theirs).
AccessibilityCommands.swift and CommandPalette.swift auto-merged with both
enum cases, entries, and palette actions.

Ran: cd apps/mac && swift test --filter 'GoToLineTests|CommandTableTests'
Executed 17 tests, with 0 failures (0 unexpected) in 0.125 (0.126) seconds.
grep -rn '<<<<<<<\|>>>>>>>' apps/mac: empty. README shortcuts unique.

Next: merge origin/main into editor-folding (#423).

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
d-q222 added a commit that referenced this pull request Sep 14, 2026
…stics beside links

Merged origin/main (7f67984) into agent/daniel-parent/mac-v2-diagnostics. Conflicts:
EditorDiagnostics.swift — kept main's CaretFix/fixOffered (#445) and mechanicalEdit
  from both forms (help.replacement else suggestion).
PreviewV2View.swift — request display-list-v2 + images + links + diagnostics.
RenderingV2.swift — both diagnosticsCapability and linksCapability (Mac/iOS
  share the file via hardlink).
EditorDiagnosticsQuickFixTests.swift — kept #363 suggestion/help-wins mapping
  test (not a second Tab-accept path).
V2ImageTests.swift — suffix(4) includes links and diagnostics.
display.rs — kept producer comment (suggestion serialised only when
  Wire.diagnostics is set); #358 merge is next and will take that file.

Ran: git merge origin/main (conflicted, then resolved as above). Tests not run
on this checkpoint.

Next: git merge origin/agent/daniel-parent/v2-structured-diagnostics (ef130a7);
take #358's display.rs on any conflict.

Open questions: whether document-runtime should also allowlist
display-list-v2-links (main requests it; this crate still does not). Out of
#363 scope unless the producer merge requires it.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
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.

2 participants