Open ZwipZwapZapony opened 7 months ago
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