Skip to content

fix(cursor): z-stacking suppression for occluded cursors (A24)#86

Merged
re-marked merged 2 commits into
mainfrom
fix/cursor-z-stacking
May 9, 2026
Merged

fix(cursor): z-stacking suppression for occluded cursors (A24)#86
re-marked merged 2 commits into
mainfrom
fix/cursor-z-stacking

Conversation

@re-marked

Copy link
Copy Markdown
Owner

Closes #83 (A24).

What

Cursor declarations now follow z-stacking. At finalize time in `ink.tsx`, hit-test the declared screen cell. If the topmost painted element isn't the declared node or a descendant of it, suppress the cursor — something else paints on top.

Symptom this fixes: a background ``'s bar/block cursor renders through any modal-shaped Box on top, even though the modal occludes the cell visually. Per Mark's repro at #83, the cursor visibly bleeds inside the modal frame.

How

  • New `cursor-visibility.ts` with `isDescendantOrSelf` + `isCursorVisibleAt(root, declNode, col, row)`. Uses the existing z-aware `hitTest` so the predicate matches what the renderer actually paints.
  • One call in `ink.tsx`'s cursor-finalize block: if `!isCursorVisibleAt(...)`, set `target = null` (existing code already handles `null` target as "don't park").

Modal-over-input that DOES contain a focused TextInput: the inner input's `useDeclaredCursor` wins last-write-wins; hit-test at the cursor cell returns the inner input (descendant of the modal), which IS the declared node — so the cursor parks correctly inside the modal. No regression.

Tests

11 new tests in `cursor-visibility.test.ts`:

  • `isDescendantOrSelf` (4): self, descendant, unrelated, reverse direction
  • `isCursorVisibleAt` (7): declared cell on declarer, on descendant, modal-over-input (the A24 repro), modal off-to-the-side, focused-input-inside-modal, off any rendered element, sibling high-z but not covering

728 tests passing (was 717; +11). typecheck / lint / build clean.

Out of scope (future)

  • `` opt-out for non-modal subtrees that want to suppress cursors below them. Mark's original A24 spec listed it as a complement to z-stacking, not a replacement; ship as a follow-up if a real consumer asks.
  • Cursor-stacking aware of multiple competing declarations (e.g. "multiple TextInputs in different windows, each declares"). Today it's still last-write-wins for the DECLARATION; the new check just gates whether the latest declaration RENDERS. Solving multi-declaration arbitration cleanly is part of the proper Window primitive (A4: No window primitive — Draggable + Resizable don't compose #56).

…#83)

Cursor declarations now follow z-stacking: at finalize time, hit-test
the declared cell. If the topmost painted element isn't the declared
node or a descendant, suppress the cursor instead of parking it.
Modals over TextInputs no longer leak the input's caret through the
modal frame.

Helper extracted to cursor-visibility.ts for testability.

Co-Authored-By: Mark <psyhik17@gmail.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@re-marked re-marked added the source:shakedown Imported from the local Yokai shakedown issue list label May 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a6527d101

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +46 to +48
const hit = hitTest(root, col, row)
if (hit === null) return false
return isDescendantOrSelf(hit, declaredNode)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't treat layout-only boxes as cursor occluders

When a higher-z absolute Box is used only as a positioning/layout wrapper (no backgroundColor, opaque, border, or child at this cell), it does not actually write any terminal cells over the focused input, but hitTest still returns that Box because the point is inside its layout rect. This makes the new visibility check hide the TextInput cursor even though the underlying input remains visible; for example, an empty transparent overlay wrapper covering the screen will suppress every cursor below it. The occlusion test needs to account for what painted the cell, not just which layout rect contains it.

Useful? React with 👍 / 👎.

@re-marked
re-marked merged commit aa227b3 into main May 9, 2026
1 check passed
@re-marked
re-marked deleted the fix/cursor-z-stacking branch May 9, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

source:shakedown Imported from the local Yokai shakedown issue list

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A24: Cursor declarations from occluded subtrees aren't suppressed

1 participant