-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Shift+Tab crashes on empty lines #1621
Comments
This doesn't happen on empty lines that are empty because the previous content was deleted. It only happens on newly created (unedited) empty lines |
I traced the problem to this code in TextEditor.cpp auto spacesToRemove = (cindex % mTabSize);
if (spacesToRemove == 0) spacesToRemove = 4;
for (int32_t j = 0; j < spacesToRemove; j++) {
if ((line.begin() + cindex - 1)->mChar == ' ') {
line.erase(line.begin() + cindex - 1);
cindex -= 1;
}
} spacesToRemove is 4 and cindex is 0. line is size 0 so (line.begin()-1)->mChar segvs. A simple fix is to add this line before for loop spacesToRemove = std::min(spacesToRemove, (int32_t) line.size()); I tested it with lines with 0,1,2,3 and 4 spaces and it deletes the spaces if there are any and does nothing if line is empty. This will be included in my next text editor enhancements pr. |
Operating System
Windows
What's the issue you encountered?
In the Pattern Editor, pressing Tab inserts (up to) four spaces to indent a line, and pressing Shift+Tab removes (up to) four spaces to un-indent a line. If the text cursor is on a completely empty line, pressing Shift+Tab crashes ImHex.
How can the issue be reproduced?
In the Pattern Editor, move the text cursor to an empty line, and press Shift+Tab.
ImHex Version
v1.33.2
ImHex Build Type
Installation type
Portable zip from the GitHub Releases page
Additional context?
No response
The text was updated successfully, but these errors were encountered: