godot
godot copied to clipboard
TextEdit caret line selection raises: Index p_column = N is out of bounds
Godot version
4.0.beta17
System information
Linux
Issue description
This issue is very similar to #69011 and #69055 but I ran into this error in latest beta.
scene/gui/text_edit.cpp:4943 - Index p_column = 6 is out of bounds (text[carets[p_caret].selection.selecting_line].length() + 1 = 6).
Steps to reproduce
- Open the script editor
- Select any line
- Press Tab to indent this line
- Remove selection
- Select the line again
- Press Shift+Tab to unindent
- Click after the end of the line
- The error happens

Minimal reproduction project
not needed
The same error happens when using "Convert Indent to Tabs" instead of indent/unindent (but I'm too lazy to make another gif). I think it always happens when the selected line gets shorter
CC @Paulb23 @KoBeWi
Working on it. There's more to this bug than meets the eye, though I'm not going to open separate bug reports. If someone else wants to work on this now, please poke me so I can explain, I'll keep trying to solve it myself for now
I explained what causes the bug and a possible easy patch in the PR above. Though right now, I'm trying to rework the TextEdit selection system to be simpler and less bug-prone.
Can you still reproduce this in 4.0.3 and 4.1-beta3 or later?
@akien-mga yes
Yeah, nothing about the underlying problems was solved. Text selection still needs an overhaul and to consistently be updated when text with selections is moved.
I found another way this happens:
- Select text
- Toggle Comment
- Deselect
- Select again
- Toggle Comment
- Click at the end
I'm running v4.1.rc1.official [1f9e540f1]
NOTE: Even though I'm demonstrating at the end of the script, the same happens if I do it anywhere in the middle of the script.
Also, I believe https://github.com/godotengine/godot/issues/74400 is the same issue.
See also: https://github.com/godotengine/godot/issues/69011 and https://github.com/godotengine/godot/issues/67828
Yeah, everything that can remove characters from a line while its end is selected would have this issue; untoggling comments is one of those things. Again, the PR I made above that was closed explains it, it's just hard to solve. Me and Paulb seem to have settled down on needing to rework the whole text selection system of TextEdit to rely on less information and to update said information more consistently, since the problem is that when a line is updated, we don't update the "pivot" of the selection.
Ideally, the pivot should be a bool saying if it's the beginning or the end of the selection, which would make it impossible that it goes to an invalid position. I'm looking to make this change in LineEdit first - I started it, but got burned out with the script editor :sweat: still on my plans, hopefully I can make the refactor for 4.2