Skip to content

Commit ca2f9f1

Browse files
authored
Merge pull request #166 from ocornut/fix_for_192
Fixes for latest dear imgui (tested with 1.92.5)
2 parents 0a88824 + 7454c1f commit ca2f9f1

1 file changed

Lines changed: 31 additions & 32 deletions

File tree

TextEditor.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include "TextEditor.h"
88

9-
#define IMGUI_DEFINE_MATH_OPERATORS
10-
#include "imgui.h" // for imGui::GetCurrentWindow()
9+
#include "imgui.h"
1110

1211
// TODO
1312
// - multiline comments vs single-line: latter is blocking start of a ML
@@ -419,7 +418,7 @@ TextEditor::Coordinates TextEditor::FindWordEnd(const Coordinates & aFrom) const
419418
if (cindex >= (int)line.size())
420419
return at;
421420

422-
bool prevspace = (bool)isspace(line[cindex].mChar);
421+
bool prevspace = isspace(line[cindex].mChar) != 0;
423422
auto cstart = (PaletteIndex)line[cindex].mColorIndex;
424423
while (cindex < (int)line.size())
425424
{
@@ -453,7 +452,7 @@ TextEditor::Coordinates TextEditor::FindNextWord(const Coordinates & aFrom) cons
453452
if (cindex < (int)mLines[at.mLine].size())
454453
{
455454
auto& line = mLines[at.mLine];
456-
isword = isalnum(line[cindex].mChar);
455+
isword = isalnum(line[cindex].mChar) != 0;
457456
skip = isword;
458457
}
459458

@@ -468,7 +467,7 @@ TextEditor::Coordinates TextEditor::FindNextWord(const Coordinates & aFrom) cons
468467
auto& line = mLines[at.mLine];
469468
if (cindex < (int)line.size())
470469
{
471-
isword = isalnum(line[cindex].mChar);
470+
isword = isalnum(line[cindex].mChar) != 0;
472471

473472
if (isword && !skip)
474473
return Coordinates(at.mLine, GetCharacterColumn(at.mLine, cindex));
@@ -711,55 +710,55 @@ void TextEditor::HandleKeyboardInputs()
711710
io.WantCaptureKeyboard = true;
712711
io.WantTextInput = true;
713712

714-
if (!IsReadOnly() && ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Z)))
713+
if (!IsReadOnly() && ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Z))
715714
Undo();
716-
else if (!IsReadOnly() && !ctrl && !shift && alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Backspace)))
715+
else if (!IsReadOnly() && !ctrl && !shift && alt && ImGui::IsKeyPressed(ImGuiKey_Backspace))
717716
Undo();
718-
else if (!IsReadOnly() && ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Y)))
717+
else if (!IsReadOnly() && ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Y))
719718
Redo();
720-
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow)))
719+
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGuiKey_UpArrow))
721720
MoveUp(1, shift);
722-
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow)))
721+
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGuiKey_DownArrow))
723722
MoveDown(1, shift);
724-
else if (!alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_LeftArrow)))
723+
else if (!alt && ImGui::IsKeyPressed(ImGuiKey_LeftArrow))
725724
MoveLeft(1, shift, ctrl);
726-
else if (!alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_RightArrow)))
725+
else if (!alt && ImGui::IsKeyPressed(ImGuiKey_RightArrow))
727726
MoveRight(1, shift, ctrl);
728-
else if (!alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_PageUp)))
727+
else if (!alt && ImGui::IsKeyPressed(ImGuiKey_PageUp))
729728
MoveUp(GetPageSize() - 4, shift);
730-
else if (!alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_PageDown)))
729+
else if (!alt && ImGui::IsKeyPressed(ImGuiKey_PageDown))
731730
MoveDown(GetPageSize() - 4, shift);
732-
else if (!alt && ctrl && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Home)))
731+
else if (!alt && ctrl && ImGui::IsKeyPressed(ImGuiKey_Home))
733732
MoveTop(shift);
734-
else if (ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_End)))
733+
else if (ctrl && !alt && ImGui::IsKeyPressed(ImGuiKey_End))
735734
MoveBottom(shift);
736-
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Home)))
735+
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGuiKey_Home))
737736
MoveHome(shift);
738-
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_End)))
737+
else if (!ctrl && !alt && ImGui::IsKeyPressed(ImGuiKey_End))
739738
MoveEnd(shift);
740-
else if (!IsReadOnly() && !ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Delete)))
739+
else if (!IsReadOnly() && !ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Delete))
741740
Delete();
742-
else if (!IsReadOnly() && !ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Backspace)))
741+
else if (!IsReadOnly() && !ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Backspace))
743742
Backspace();
744-
else if (!ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Insert)))
743+
else if (!ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Insert))
745744
mOverwrite ^= true;
746-
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Insert)))
745+
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Insert))
747746
Copy();
748-
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_C)))
747+
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_C))
749748
Copy();
750-
else if (!IsReadOnly() && !ctrl && shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Insert)))
749+
else if (!IsReadOnly() && !ctrl && shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Insert))
751750
Paste();
752-
else if (!IsReadOnly() && ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_V)))
751+
else if (!IsReadOnly() && ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_V))
753752
Paste();
754-
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_X)))
753+
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_X))
755754
Cut();
756-
else if (!ctrl && shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Delete)))
755+
else if (!ctrl && shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Delete))
757756
Cut();
758-
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_A)))
757+
else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_A))
759758
SelectAll();
760-
else if (!IsReadOnly() && !ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)))
759+
else if (!IsReadOnly() && !ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGuiKey_Enter))
761760
EnterCharacter('\n', false);
762-
else if (!IsReadOnly() && !ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Tab)))
761+
else if (!IsReadOnly() && !ctrl && !alt && ImGui::IsKeyPressed(ImGuiKey_Tab))
763762
EnterCharacter('\t', shift);
764763

765764
if (!IsReadOnly() && !io.InputQueueCharacters.empty())
@@ -1132,7 +1131,7 @@ void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder)
11321131
if (mHandleKeyboardInputs)
11331132
{
11341133
HandleKeyboardInputs();
1135-
ImGui::PushAllowKeyboardFocus(true);
1134+
ImGui::PushItemFlag(ImGuiItemFlags_NoTabStop, false);
11361135
}
11371136

11381137
if (mHandleMouseInputs)
@@ -1142,7 +1141,7 @@ void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder)
11421141
Render();
11431142

11441143
if (mHandleKeyboardInputs)
1145-
ImGui::PopAllowKeyboardFocus();
1144+
ImGui::PopItemFlag();
11461145

11471146
if (!mIgnoreImGuiChild)
11481147
ImGui::EndChild();

0 commit comments

Comments
 (0)