Skip to content

[Bug] Caret vertical position is incorrect and disappears in multi-line aligned environment #3044

Description

@tingyuzaixiao

Bug Description

When programmatically setting the value of a MathField to a multi-line aligned environment and moving the caret to a subsequent row (e.g., after &=), the caret's Y-coordinate is severely miscalculated.

Instead of aligning with the baseline of the current row, the caret renders vertically displaced, appearing exactly in the gap between the rows.

Furthermore, if the first column of the new row is completely empty (e.g., using \\ &=), the caret disappears entirely. Adding an empty LaTeX group {} (e.g., \\ {} &=) prevents the disappearance, but the incorrect vertical Y-offset bug persists.

Steps to Reproduce

  1. Initialize a MathField.
  2. Execute the following code to update the value and position the caret:
// Scenario 1: Caret disappears
mf.setValue('\\begin{aligned} a &= b + c \\\\ &= \\end{aligned}', { selectionMode: 'after' });
mf.focus();

// Scenario 2: Caret is visible but vertically displaced (floating between rows)
mf.setValue('\\begin{aligned} a &= b + c \\\\ {} &= \\end{aligned}', { selectionMode: 'after' });
mf.focus();

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions