def update(self):
        """Keep cursor inside the entry's rect.

        This clamps the cursor to the entry's rect, moving
        the line along by the same amount of movement.
        """
        ### reference the cursor rect locally and obtain
        ### a copy of it clamped to the entry's rect

        rect = self.rect
        clamped = rect.clamp(self.entry_widget.rect)

        ### if such rects are equal, it means the clamping
        ### didn't need to move the cursor's copy, cause it
        ### was already inside the entry's rect; if this is
        ### the case, there's nothing left to do, so we can
        ### return right away
        if clamped == rect:
            return

        ### otherwise, it means we need to clamp the cursor
        ### and move the text (represented here by the line)
        ### along with it

        ## calculate the difference between the topleft
        ## of the clamped rect and the topleft of the
        ## original rect
        delta = Vector2(clamped.topleft) - rect.topleft

        ## finally offset the cursor and line with the delta

        rect.move_ip(delta)
        self.line.rect.move_ip(delta)
Keep cursor inside the entry's rect.

        This clamps the cursor to the entry's rect, moving
        the line along by the same amount of movement.
        
nodezator/textman/entryedition/cursor.py