# Buggy code
def vertices(self):
    textbox = self.textbox
    # check we have a caret index
    if self.index is None or self.index > len(textbox._layoutText):
        self.index = len(textbox._layoutText)
    if self.index < 0:
        self.index = 0
    # get the verts of character next to caret (chr is the next one so use
    # left edge unless last index then use the right of prev chr)
    # lastChar = [bottLeft, topLeft, **bottRight**, **topRight**]
    ii = self.index
    if textbox.vertices.shape[0] == 0:
        verts = textbox._getStartingVertices() / textbox._pixelScaling
        verts[:, 1] = verts[:, 1]
        verts[:, 0] = verts[:, 0] + float(textbox._anchorOffsetX)
    else:
        if self.index >= len(textbox._lineNs):  # caret is after last chr
            chrVerts = textbox.vertices[range((ii - 1) * 4, (ii - 1) * 4 + 4)]
            x = chrVerts[2, 0]  # x-coord of left edge (of final char)
        else:
            chrVerts = textbox.vertices[range(ii * 4, ii * 4 + 4)]
            x = chrVerts[1, 0]  # x-coord of right edge
        # the y locations are the top and bottom of this line
        y1 = textbox._lineBottoms[self.row] / textbox._pixelScaling
        y2 = textbox._lineTops[self.row] / textbox._pixelScaling
        # char x pos has been corrected for anchor already but lines haven't
        verts = np.array([[x, y1], [x, y2]]) + (0, textbox._anchorOffsetY)

    return convertToPix(
        vertices=verts, pos=textbox.pos, win=textbox.win, units=textbox.units
    )


# Traceback (IndexError)
Traceback (most recent call last):
File "textbox_editable.py", line 67, in <module>
win.flip()
File "psychopy\psychopy\visual\window.py", line 1026, in flip
thisStim.draw()
File "psychopy\psychopy\visual\textbox2\textbox2.py", line 551, in draw
self.caret.draw()
File "psychopy\psychopy\visual\textbox2\textbox2.py", line 848, in draw
gl.glVertex2f(self.vertices[0, 0], self.vertices[0, 1])
File "psychopy\psychopy\visual\textbox2\textbox2.py", line 946, in vertices
chrVerts = textbox.vertices[range((ii-1) * 4, (ii-1) * 4 + 4)]
IndexError: index 1212 is out of bounds for axis 0 with size 1176

# Fixed code
def vertices(self):
    textbox = self.textbox
    # check we have a caret index
    if self.index is None or self.index > len(textbox.visibleText):
        self.index = len(textbox.visibleText)
    if self.index < 0:
        self.index = 0
    # get the verts of character next to caret (chr is the next one so use
    # left edge unless last index then use the right of prev chr)
    # lastChar = [bottLeft, topLeft, **bottRight**, **topRight**]
    ii = self.index
    if textbox.vertices.shape[0] == 0:
        verts = textbox._getStartingVertices() / textbox._pixelScaling
        verts[:, 1] = verts[:, 1]
        verts[:, 0] = verts[:, 0] + float(textbox._anchorOffsetX)
    else:
        if self.index >= len(textbox._lineNs):  # caret is after last chr
            chrVerts = textbox.vertices[range((ii - 1) * 4, (ii - 1) * 4 + 4)]
            x = chrVerts[2, 0]  # x-coord of left edge (of final char)
        else:
            chrVerts = textbox.vertices[range(ii * 4, ii * 4 + 4)]
            x = chrVerts[1, 0]  # x-coord of right edge
        # the y locations are the top and bottom of this line
        y1 = textbox._lineBottoms[self.row] / textbox._pixelScaling
        y2 = textbox._lineTops[self.row] / textbox._pixelScaling
        # char x pos has been corrected for anchor already but lines haven't
        verts = np.array([[x, y1], [x, y2]]) + (0, textbox._anchorOffsetY)

    return convertToPix(
        vertices=verts, pos=textbox.pos, win=textbox.win, units=textbox.units
    )