zed-industries/zed · error

prepaint has not been performed

Error message

prepaint has not been performed

What it means

The sibling expect in index_for_position: measurement exists but bounds were not filled, meaning prepaint never ran for the text element before index_for_position was called. The position-to-index lookup depends on prepaint-computed geometry, so calling it between layout and prepaint panics.

Source

Thrown at crates/gpui/src/elements/text.rs:837

                text_style.text_align,
                Some(bounds),
                window,
                cx,
            )
            .log_err();
            line_origin.y += line.size(line_height).height;
        }
    }

    /// Get the byte index into the input of the pixel position.
    pub fn index_for_position(&self, mut position: Point<Pixels>) -> Result<usize, usize> {
        let element_state = self.0.borrow();
        let element_state = element_state
            .as_ref()
            .expect("measurement has not been performed");
        let bounds = element_state
            .bounds
            .expect("prepaint has not been performed");

        if position.y < bounds.top() {
            return Err(0);
        }

        let line_height = element_state.line_height;
        let mut line_origin = bounds.origin;
        let mut line_start_ix = 0;
        for line in &element_state.lines {
            let line_bottom = line_origin.y + line.size(line_height).height;
            if position.y > line_bottom {
                line_origin.y = line_bottom;
                line_start_ix += line.len() + 1;
            } else {
                let position_within_line = position - line_origin;
                match line.index_for_position(position_within_line, line_height) {
                    Ok(index_within_line) => return Ok(line_start_ix + index_within_line),
                    Err(index_within_line) => return Err(line_start_ix + index_within_line),

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Call index_for_position only after prepaint has completed for the current frame
  2. Store prepaint bounds in element state during prepaint and verify presence
  3. Return an error/Option instead of expecting when geometry is unavailable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui/src/elements/text.rs:837 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/57b864d1c18aefeb. Report an issue: GitHub.