zed-industries/zed · error

measurement has not been performed

Error message

measurement has not been performed

What it means

TextShapeRef::index_for_position requires measurement (layout) to have run; the element state is None because the text element's request_layout/measurement never executed before the call. Calling index_for_position before the element has been laid out and painted in the current frame panics.

Source

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

            line.paint(
                line_origin,
                line_height,
                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;

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Only call index_for_position after the element completed request_layout/prepaint in this frame
  2. Cache measured state across frames if hit-testing happens outside paint
  3. Guard calls with an existence check on the element state instead of expecting
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui/src/elements/text.rs:834 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/523d557e02e86220. Report an issue: GitHub.