fix: CTRL + A not selecting last line in the text editor

This commit is contained in:
WerWolv
2025-07-12 21:46:09 +02:00
parent 58d0d09eae
commit 01d0f03fdd

View File

@@ -472,6 +472,8 @@ int TextEditor::GetCharacterIndex(const Coordinates &aCoordinates) const {
int TextEditor::GetCharacterColumn(int aLine, int aIndex) const {
if (aLine >= mLines.size())
return 0;
if (aLine < 0)
return 0;
auto &line = mLines[aLine];
int col = 0;
int i = 0;
@@ -498,6 +500,8 @@ int TextEditor::GetStringCharacterCount(std::string str) const {
int TextEditor::GetLineCharacterCount(int aLine) const {
if (aLine >= mLines.size())
return 0;
if (aLine < 0)
return 0;
auto &line = mLines[aLine];
int c = 0;
for (unsigned i = 0; i < line.size(); c++)
@@ -508,6 +512,8 @@ int TextEditor::GetLineCharacterCount(int aLine) const {
unsigned long long TextEditor::GetLineByteCount(int aLine) const {
if (aLine >= mLines.size())
return 0;
if (aLine < 0)
return 0;
auto &line = mLines[aLine];
return line.size();
}
@@ -515,6 +521,8 @@ unsigned long long TextEditor::GetLineByteCount(int aLine) const {
int TextEditor::GetLineMaxColumn(int aLine) const {
if (aLine >= mLines.size())
return 0;
if (aLine < 0)
return 0;
auto &line = mLines[aLine];
int col = 0;
for (unsigned i = 0; i < line.size();) {
@@ -2011,7 +2019,10 @@ void TextEditor::SelectWordUnderCursor() {
}
void TextEditor::SelectAll() {
SetSelection(Coordinates(0, 0), Coordinates((int)mLines.size(), 0));
if (isEmpty())
return;
SetSelection(Coordinates(0, 0), Coordinates((int)mLines.size(), mLines.empty() ? 0 : GetLineMaxColumn((int)mLines.size() - 1)));
}
bool TextEditor::HasSelection() const {