From 913006e7079c4d31ccc72212b0d2b159f703e831 Mon Sep 17 00:00:00 2001 From: bert0ns Date: Wed, 8 Jul 2026 01:58:03 +0200 Subject: [PATCH 1/3] Fix EnsureCursorVisible pixel coordinate mismatch bug --- TextEditor.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/TextEditor.cpp b/TextEditor.cpp index 8d16d619..284631b9 100644 --- a/TextEditor.cpp +++ b/TextEditor.cpp @@ -2479,23 +2479,24 @@ void TextEditor::EnsureCursorVisible() auto height = ImGui::GetWindowHeight(); auto width = ImGui::GetWindowWidth(); - auto top = 1 + (int)ceil(scrollY / mCharAdvance.y); - auto bottom = (int)ceil((scrollY + height) / mCharAdvance.y); - - auto left = (int)ceil(scrollX / mCharAdvance.x); - auto right = (int)ceil((scrollX + width) / mCharAdvance.x); - auto pos = GetActualCursorCoordinates(); auto len = TextDistanceToLineStart(pos); - if (pos.mLine < top) - ImGui::SetScrollY(std::max(0.0f, (pos.mLine - 1) * mCharAdvance.y)); - if (pos.mLine > bottom - 4) - ImGui::SetScrollY(std::max(0.0f, (pos.mLine + 4) * mCharAdvance.y - height)); - if (len + mTextStart < left + 4) - ImGui::SetScrollX(std::max(0.0f, len + mTextStart - 4)); - if (len + mTextStart > right - 4) - ImGui::SetScrollX(std::max(0.0f, len + mTextStart + 4 - width)); + float padY = std::min(2.0f * mCharAdvance.y, height * 0.25f); + float padX = std::min(4.0f * mCharAdvance.x, width * 0.25f); + + float cursorPosY = pos.mLine * mCharAdvance.y; + float cursorPosX = len + mTextStart; + + if (cursorPosY < scrollY + padY) + ImGui::SetScrollY(std::max(0.0f, cursorPosY - padY)); + if (cursorPosY + mCharAdvance.y > scrollY + height - padY) + ImGui::SetScrollY(std::max(0.0f, cursorPosY + mCharAdvance.y - height + padY)); + + if (cursorPosX < scrollX + padX) + ImGui::SetScrollX(std::max(0.0f, cursorPosX - padX)); + if (cursorPosX > scrollX + width - padX) + ImGui::SetScrollX(std::max(0.0f, cursorPosX - width + padX)); } int TextEditor::GetPageSize() const From 3ae57325cac4e4b7a9aa6f4b551a9a30369e66b3 Mon Sep 17 00:00:00 2001 From: bert0ns Date: Wed, 8 Jul 2026 01:58:48 +0200 Subject: [PATCH 2/3] fix: typo in contributing.md --- CONTRIBUTING | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING b/CONTRIBUTING index 73ab1619..0b5ea818 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -6,6 +6,6 @@ Whem contributing, please follow the following guidelines. I will keep it update - Please submit to the 'dev' branch first for testing, and it will be merged to 'main' if it seems to work fine. I would like try keep 'master' in a good working condition, as more and more people are using it. - Please send your submissions in small, well defined requests, i. e. do not accumulate many unrelated changes in one large pull request. Keep your submissions as small as possible, it will make everyone's life easier. - Avoid using ImGui internal since it would make the source fragile against internal changes in ImGui. -- Try to keep the perormance high within the render function. Try to avoid doing anything which leads to memory allocations (like using temporary std::string, std::vector variables), or complex algorithm. If you really have to, try to amortise it between frames. +- Try to keep the performance high within the render function. Try to avoid doing anything which leads to memory allocations (like using temporary std::string, std::vector variables), or complex algorithm. If you really have to, try to amortise it between frames. Thank you. :) From 38b101eabaef1af0ef74a13785d9fc53fe577863 Mon Sep 17 00:00:00 2001 From: bert0ns Date: Wed, 8 Jul 2026 01:58:48 +0200 Subject: [PATCH 3/3] Fix EnsureCursorVisible pixel coordinate mismatch and padding clamp --- TextEditor.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/TextEditor.cpp b/TextEditor.cpp index 284631b9..c539e5a3 100644 --- a/TextEditor.cpp +++ b/TextEditor.cpp @@ -1149,7 +1149,7 @@ void TextEditor::Render() } - ImGui::Dummy(ImVec2((longest + 2), mLines.size() * mCharAdvance.y)); + ImGui::Dummy(ImVec2((longest + 2 + 4.0f * mCharAdvance.x), mLines.size() * mCharAdvance.y)); if (mScrollToCursor) { @@ -2482,16 +2482,15 @@ void TextEditor::EnsureCursorVisible() auto pos = GetActualCursorCoordinates(); auto len = TextDistanceToLineStart(pos); - float padY = std::min(2.0f * mCharAdvance.y, height * 0.25f); float padX = std::min(4.0f * mCharAdvance.x, width * 0.25f); float cursorPosY = pos.mLine * mCharAdvance.y; float cursorPosX = len + mTextStart; - if (cursorPosY < scrollY + padY) - ImGui::SetScrollY(std::max(0.0f, cursorPosY - padY)); - if (cursorPosY + mCharAdvance.y > scrollY + height - padY) - ImGui::SetScrollY(std::max(0.0f, cursorPosY + mCharAdvance.y - height + padY)); + if (cursorPosY < scrollY) + ImGui::SetScrollY(std::max(0.0f, cursorPosY)); + if (cursorPosY + mCharAdvance.y > scrollY + height) + ImGui::SetScrollY(std::max(0.0f, cursorPosY + mCharAdvance.y - height)); if (cursorPosX < scrollX + padX) ImGui::SetScrollX(std::max(0.0f, cursorPosX - padX));