fix: SHIFT + Tab not removing tabs in pattern editor

This commit is contained in:
WerWolv 2023-11-15 10:04:48 +01:00
parent 2c0553f8fd
commit a561cee54b
1 changed files with 20 additions and 4 deletions

View File

@ -1184,10 +1184,26 @@ void TextEditor::EnterCharacter(ImWchar aChar, bool aShift) {
} else if (aChar == '\t') { } else if (aChar == '\t') {
auto &line = mLines[coord.mLine]; auto &line = mLines[coord.mLine];
auto cindex = GetCharacterIndex(coord); auto cindex = GetCharacterIndex(coord);
auto spacesToInsert = mTabSize - (cindex % mTabSize);
for (int j = 0; j < spacesToInsert; j++) if (!aShift) {
line.insert(line.begin() + cindex, Glyph(' ', PaletteIndex::Background)); auto spacesToInsert = mTabSize - (cindex % mTabSize);
SetCursorPosition(Coordinates(coord.mLine, GetCharacterColumn(coord.mLine, cindex + spacesToInsert))); for (int j = 0; j < spacesToInsert; j++)
line.insert(line.begin() + cindex, Glyph(' ', PaletteIndex::Background));
SetCursorPosition(Coordinates(coord.mLine, GetCharacterColumn(coord.mLine, cindex + spacesToInsert)));
} else {
auto spacesToRemove = (cindex % mTabSize);
if (spacesToRemove == 0) spacesToRemove = 4;
for (int j = 0; j < spacesToRemove; j++) {
if ((line.begin() + cindex - 1)->mChar == ' ') {
line.erase(line.begin() + cindex - 1);
cindex -= 1;
}
}
SetCursorPosition(Coordinates(coord.mLine, GetCharacterColumn(coord.mLine, std::max(0, cindex))));
}
} else { } else {
char buf[7]; char buf[7];
int e = ImTextCharToUtf8(buf, 7, aChar); int e = ImTextCharToUtf8(buf, 7, aChar);