      // Update the EditContext's selection bounds to match the position and size of the caret.
        const selectionBound = computeCharacterBound(caretIndex);
        selectionBound.width = CARET_WIDTH;
        editContext.updateSelectionBounds(selectionBound);
      } else {
        // Render the text selection.
        const startX = TEXT_ANCHOR_X + canvasCtx.measureText(editContext.text.substring(0, selectionStart)).width;
        const endX = TEXT_ANCHOR_X + canvasCtx.measureText(editContext.text.sub