AvalonEdit
AvalonEdit copied to clipboard
Make Y offset to be a multiple of line height
There is a possible incorrect behavior I've found I would like to discuss:
When you navigate with page down, the caret is forced into view by TextView.MakeVisible(), but that often makes the scroll Y offset to be unaligned respect to text lines, causing a partially covered top line (very noticeable with big fonts).
IMO, the correct behavior should be forcing newScrollOffset.Y to be a perfect multiple of DefaultLineHeight, so that the first line is always "in sync". This is what all other editors mostly do (e.g. VS).
I was thinking something like this:
newScrollOffset.Y = Math.Floor(newScrollOffset.Y / DefaultLineHeight) * DefaultLineHeight;
But I don't know if that fix is correct to, because of this DefaultLineHeight comment:
/// Gets the default line height. This is the height of an empty line or a line containing regular text.
/// Lines that include formatted text or custom UI elements may have a different line height.
What do you think?
the fix I mentioned seems to work nicely (I am using it in my fork), but has some side-effects I am not sure of.
I think along with it, there's scroll bar dragging and mouse wheeling that need to be aligned too.
Ok, I made another fix, I've moved the alignment operation within IScrollInfo.SetVerticalOffset(),
so that every change in Y offset is aligned with DefaultLineHeight. Seem to work better than before.
Also:
- I'm using
Roundin place ofFloor - Fixed the impossibility to scroll to last line (by dragging scroll bar) if not a multiple of line height
I closed my own pull request, as it had too many uncontrollable side effects.
I leave the issue open, in case someone else has a better solution.