From 3bcfa7e10bb4edcfa8bb97d55a5c61e9c29bb8b2 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 14 Nov 2022 09:44:10 +0100 Subject: [PATCH] ux: Make the pattern language text editor always insert spaces instead of tabs --- lib/external/imgui/source/TextEditor.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/external/imgui/source/TextEditor.cpp b/lib/external/imgui/source/TextEditor.cpp index 10fdf2b4c..f7e1c8cd0 100644 --- a/lib/external/imgui/source/TextEditor.cpp +++ b/lib/external/imgui/source/TextEditor.cpp @@ -1095,7 +1095,8 @@ void TextEditor::EnterCharacter(ImWchar aChar, bool aShift) { } } } else { - line.insert(line.begin(), Glyph('\t', TextEditor::PaletteIndex::Background)); + for (int j = start.mColumn % mTabSize; j < mTabSize; j++) + line.insert(line.begin(), Glyph(' ', PaletteIndex::Background)); modified = true; } } @@ -1156,6 +1157,13 @@ void TextEditor::EnterCharacter(ImWchar aChar, bool aShift) { line.erase(line.begin() + cindex, line.begin() + line.size()); SetCursorPosition(Coordinates(coord.mLine + 1, GetCharacterColumn(coord.mLine + 1, (int)whitespaceSize))); u.mAdded = (char)aChar; + } else if (aChar == '\t') { + auto &line = mLines[coord.mLine]; + auto cindex = GetCharacterIndex(coord); + auto spacesToInsert = mTabSize - (cindex % mTabSize); + 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 { char buf[7]; int e = ImTextCharToUtf8(buf, 7, aChar);