Z index feature#2291
Conversation
📝 WalkthroughWalkthroughLayerManager now exposes methods to move an identified layer above or below every other layer by recalculating its z-index. ChangesLayer ordering
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/terminal/LayerManager.ts`:
- Around line 118-153: Update bringToFront() and sendToBack() so that whenever
the target layer’s zIndex changes, all visible layers are marked dirty, ensuring
the render loop recomposites immediately after reordering. Reuse the existing
layer visibility and dirty-state APIs in LayerManager rather than changing
z-index behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 6a800627-ea4f-474b-bb98-a8d5f2dc6e0b
📒 Files selected for processing (1)
packages/core/src/terminal/LayerManager.ts
| /** | ||
| * Brings the specified layer to the front by assigning it a z-index higher than all others. | ||
| */ | ||
| bringToFront(id: string): void { | ||
| const layer = this._layers.get(id); | ||
| if (!layer) return; | ||
|
|
||
| let maxZ = -Infinity; | ||
| for (const l of this._layers.values()) { | ||
| if (l.id !== id && l.zIndex > maxZ) { | ||
| maxZ = l.zIndex; | ||
| } | ||
| } | ||
| if (layer.zIndex <= maxZ) { | ||
| layer.zIndex = maxZ + 1; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sends the specified layer to the back by assigning it a z-index lower than all others. | ||
| */ | ||
| sendToBack(id: string): void { | ||
| const layer = this._layers.get(id); | ||
| if (!layer) return; | ||
|
|
||
| let minZ = Infinity; | ||
| for (const l of this._layers.values()) { | ||
| if (l.id !== id && l.zIndex < minZ) { | ||
| minZ = l.zIndex; | ||
| } | ||
| } | ||
| if (layer.zIndex >= minZ) { | ||
| layer.zIndex = minZ - 1; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## LayerManager outline\n'
ast-grep outline packages/core/src/terminal/LayerManager.ts --view expanded || true
printf '\n## Search for dirty-region and redraw related symbols\n'
rg -n "dirtyRegion|hasDirtyLayers|composite\\(|mark.*Dirty|invalidate|full.*redraw|redraw" packages/core/src/terminal packages/core/src -g '*.ts' || true
printf '\n## Read LayerManager.ts around relevant sections\n'
nl -ba packages/core/src/terminal/LayerManager.ts | sed -n '1,260p'Repository: Karanjot786/TermUI
Length of output: 10867
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## LayerManager relevant sections\n'
sed -n '114,320p' packages/core/src/terminal/LayerManager.ts | cat -n
printf '\n## App render loop around layer compositing\n'
sed -n '390,455p' packages/core/src/app/App.ts | cat -n
printf '\n## Renderer invalidate usage\n'
sed -n '90,145p' packages/core/src/terminal/Renderer.ts | cat -nRepository: Karanjot786/TermUI
Length of output: 14022
Invalidate layers when z-index changes
bringToFront() and sendToBack() only update zIndex. Since the render loop skips compositing when hasDirtyLayers() is false, a layer reorder can be skipped entirely until some other change dirties a layer. Mark the visible layers dirty here so the new stacking order is rendered immediately.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/src/terminal/LayerManager.ts` around lines 118 - 153, Update
bringToFront() and sendToBack() so that whenever the target layer’s zIndex
changes, all visible layers are marked dirty, ensuring the render loop
recomposites immediately after reordering. Reuse the existing layer visibility
and dirty-state APIs in LayerManager rather than changing z-index behavior.
Description
This PR enhances the overlay layering system by introducing dynamic z-index management. It adds
bringToFront(id)andsendToBack(id)methods to theLayerManagerin@termuijs/core, allowing developers to programmatically pop modals or dropdowns to the very top of the rendering stack without hardcoding arbitraryzIndexvalues.Related Issue
Closes #2251
Which package(s)?
@termuijs/coreType of Change
type:bug)type:feature)type:docs)type:testing)type:refactor)type:design)type:accessibility)type:performance)type:devops)type:security)Checklist
needs-starcheck blocks your merge otherwise.bun vitest runbun run buildbun run typecheckCONTRIBUTING.md.type: short description.markDirty()(if your change affects rendering).anytypes without an inline comment explaining why.GSSoC 2026 Participation
https://gssoc.girlscript.org/profile/YOUR_PROFILE_ID_HEREScreenshots / Recordings (UI changes)
Notes for the Reviewer
These helper methods loop through the currently active layers in
LayerManagerto find the absolute maximum or minimum z-index currently allocated, ensuring we never cause z-index collisions when dynamically moving layers.Summary by CodeRabbit