Fix for crash which can happen if unindent operation (shift + TAB) is performed on a (selection of) line(s) which are empty.
diff --git a/TextEditor.cpp b/TextEditor.cpp
index 963e754..f59cdea 100644
--- a/TextEditor.cpp
+++ b/TextEditor.cpp
@@ -921,19 +921,25 @@
auto& line = mLines[i];
if (aShift)
{
- if (line[0].mChar == '\t')
- {
- line.erase(line.begin());
- if (i == end.mLine && end.mColumn > 0)
- end.mColumn--;
- modified = true;
- }
- else for (int j = 0; j < mTabSize && line[0].mChar == ' '; j++)
- {
- line.erase(line.begin());
- if (i == end.mLine && end.mColumn > 0)
- end.mColumn--;
- modified = true;
+ if (line.empty() == false)
+ {
+ if (line.front().mChar == '\t')
+ {
+ line.erase(line.begin());
+ if (i == end.mLine && end.mColumn > 0)
+ end.mColumn--;
+ modified = true;
+ }
+ }
+ else
+ {
+ for (int j = 0; j < mTabSize && line.empty() == false && line.front().mChar == ' '; j++)
+ {
+ line.erase(line.begin());
+ if (i == end.mLine && end.mColumn > 0)
+ end.mColumn--;
+ modified = true;
+ }
}
}
else