diff --git a/include/TextEditor.h b/include/TextEditor.h index 85c6424e..6d6eec9c 100755 --- a/include/TextEditor.h +++ b/include/TextEditor.h @@ -11,7 +11,7 @@ #include "imgui.h" /** - * https://github.com/BalazsJako/ImGuiColorTextEdit + * https://github.com/BalazsJako/ImGuiColorTextEdit (commit 6c69c306da0afb6c0b7ea51ec504aa0aae348aad) * * MIT License * diff --git a/src/imgui/TextEditor.cpp b/src/imgui/TextEditor.cpp index 4ce42f60..d03cc17b 100755 --- a/src/imgui/TextEditor.cpp +++ b/src/imgui/TextEditor.cpp @@ -7,7 +7,7 @@ #include "TextEditor.h" /** - * https://github.com/BalazsJako/ImGuiColorTextEdit + * https://github.com/BalazsJako/ImGuiColorTextEdit (commit 6c69c306da0afb6c0b7ea51ec504aa0aae348aad) */ static const int cTextStart = 7; @@ -104,7 +104,7 @@ TextEditor::Coordinates TextEditor::SanitizeCoordinates(const Coordinates & aVal auto line = aValue.mLine; auto column = aValue.mColumn; - if (line >= mLines.size()) + if (line >= (int)mLines.size()) { line = (int)mLines.size() - 1; column = mLines.empty() ? 0 : (int)mLines[line].size(); @@ -657,7 +657,8 @@ void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder) } } - snprintf(buf, 16, "%6d", lineNo + 1); + auto chars = snprintf(buf, 16, "%6d", lineNo + 1); + assert(chars >= 0 && chars < 16); drawList->AddText(ImVec2(lineStartScreenPos.x /*+ mCharAdvance.x * 1*/, lineStartScreenPos.y), mPalette[(int)PaletteIndex::LineNumber], buf); if (mState.mCursorPosition.mLine == lineNo) @@ -1027,8 +1028,11 @@ void TextEditor::MoveRight(int aAmount, bool aSelect, bool aWordMode) auto& line = mLines[mState.mCursorPosition.mLine]; if (mState.mCursorPosition.mColumn >= (int)line.size()) { - mState.mCursorPosition.mLine = std::max(0, std::min((int)mLines.size() - 1, mState.mCursorPosition.mLine + 1)); - mState.mCursorPosition.mColumn = 0; + if (mState.mCursorPosition.mLine < (int)mLines.size() - 1) + { + mState.mCursorPosition.mLine = std::max(0, std::min((int)mLines.size() - 1, mState.mCursorPosition.mLine + 1)); + mState.mCursorPosition.mColumn = 0; + } } else {