1
0
mirror of synced 2024-11-14 19:17:42 +01:00

ui: Make text editor automatically close (, [, {, " and '

This commit is contained in:
WerWolv 2021-10-19 13:22:08 +02:00
parent 58e3031510
commit 93474d7f43

View File

@ -767,8 +767,26 @@ void TextEditor::HandleKeyboardInputs()
for (int i = 0; i < io.InputQueueCharacters.Size; i++)
{
auto c = io.InputQueueCharacters[i];
if (c != 0 && (c == '\n' || c >= 32))
EnterCharacter(c, shift);
if (c != 0 && (c == '\n' || c >= 32)) {
constexpr std::array<std::pair<char, char>, 5> doubleChars = {{ { '(', ')' }, { '[', ']' }, { '{', '}' }, { '"', '"' }, {'\'', '\'' } }};
bool handled = false;
for (auto [doubleCharOpen, doubleCharClose] : doubleChars) {
if (c == doubleCharOpen) {
EnterCharacter(doubleCharOpen, shift);
auto cursorPos = GetCursorPosition();
EnterCharacter(doubleCharClose, shift);
SetCursorPosition(cursorPos);
handled = true;
break;
}
}
if (!handled)
EnterCharacter(c, shift);
}
}
io.InputQueueCharacters.resize(0);
}