The bug is now fixed, knowing that it happened at the end of a paragraph was enough to reproduce it here and thus quickly find the issue.
Inside tgui only '\n' is used so this was not related to windows. The problem happened because the contents of the line contains '\n' at the end. While you see e.g. 5 characters on the screen, the line will contain 6 characters because it also contains the newline. The caret is at position 5 and when pressing the right arrow key the code just checked if it was at the end of the line (which it isn't technically) and move it forward. The problem was solved by skipping the '\n' at the end of the line.
Inside tgui only '\n' is used so this was not related to windows. The problem happened because the contents of the line contains '\n' at the end. While you see e.g. 5 characters on the screen, the line will contain 6 characters because it also contains the newline. The caret is at position 5 and when pressing the right arrow key the code just checked if it was at the end of the line (which it isn't technically) and move it forward. The problem was solved by skipping the '\n' at the end of the line.