fix: coordinate mismatch in EnsureCursorVisible() causing 4-pixel scroll margin#172
Open
Bert0ns wants to merge 3 commits into
Open
fix: coordinate mismatch in EnsureCursorVisible() causing 4-pixel scroll margin#172Bert0ns wants to merge 3 commits into
EnsureCursorVisible() causing 4-pixel scroll margin#172Bert0ns wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: in
TextEditor::EnsureCursorVisible()where typing near the horizontal edges of the window would cause the view to scroll by exactly 1 character per keystroke, effectively pinning the cursor to the physical edge of the editor view.The Bug
The previous implementation mixed up character column indices and physical pixel floats when attempting to calculate padding bounds:
len(fromTextDistanceToLineStart) correctly returned physical pixels (float).leftandrightwere calculated by dividing scroll dimensions bymCharAdvance.x, returning character columns (int).len + mTextStart < left + 4thus incorrectly compared pixels directly to character columns.ImGui::SetScrollX()expects a pixel value. By callingImGui::SetScrollX(... - 4), the logic intended to subtract a margin of 4 characters, but mathematically subtracted exactly 4 physical pixels instead.The Fix
This PR fully normalizes the
EnsureCursorVisiblelogic to use consistent, floating-point pixel math for all boundary and padding calculations.padX= 4 characters).ImGui::Dummy(which defines the maximum horizontal scroll bounds) did not account for padding. By adding the horizontal padding to the Dummy width, it ensures that padding is maintained even when typing on the longest line of the document.std::min(..., width * 0.25f)to ensure that if the editor window is resized to be extremely small, the padding doesn't mathematically overlap and cause the scroll position to oscillate.Testing