Skip to content

Tooltip::layout panics with 'min > max' when content wider than viewport #213

Description

@JDonaghy

Repro

User reported during smoke testing of #205 slice 8 (`caf62a8`), but the bug is in the slice 1 primitive (`e1e76cd`):

```
thread 'main' panicked at .../core/src/num/f32.rs:1432:9:
min > max, or either was NaN. min = 0.0, max = -378.9336
draw_editor panic: Any { .. }
VimCode crashed.
```

Stack: `Tooltip::layout` → `f32::clamp` → panic.

Cause

`quadraui/src/primitives/tooltip.rs:202-203`:

```rust
let cx = px.clamp(viewport.x, viewport.x + viewport.width - vw);
let cy = py.clamp(viewport.y, viewport.y + viewport.height - vh);
```

If the tooltip's measured width `vw` exceeds `viewport.width`, then `viewport.x + viewport.width - vw < viewport.x`, so `min > max` and `f32::clamp` panics. Same for `vh > viewport.height`.

In the user's crash: `viewport.width - vw = -378.9`, meaning the LSP hover popup measured ~378px wider than the editor viewport.

Fix

Guard the clamp:

```rust
let max_x = (viewport.x + viewport.width - vw).max(viewport.x);
let max_y = (viewport.y + viewport.height - vh).max(viewport.y);
let cx = px.clamp(viewport.x, max_x);
let cy = py.clamp(viewport.y, max_y);
```

When the tooltip is too big to fit, pin it to the viewport top-left and let it overflow on the right/bottom (better than crashing). The consumer is responsible for choosing a reasonable width if overflow is undesirable.

Surfaced by

#205 slice 1 (`e1e76cd) — the LSP hover popup migration. The legacy renderer didn't call \Tooltip::layout` so it never hit this. Other Tooltip consumers (signature help, diff peek) build small content and don't trigger.

Tests

Add a unit test in `tooltip.rs` for `vw > viewport.width` and `vh > viewport.height` — both paths.

Files

  • `quadraui/src/primitives/tooltip.rs::Tooltip::layout` — the panicking clamp

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginfrastructureBuild, CI, distribution

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions