AvalonEdit icon indicating copy to clipboard operation
AvalonEdit copied to clipboard

Make Y offset to be a multiple of line height

Open nippur72 opened this issue 10 years ago • 4 comments

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?

nippur72 avatar May 04 '15 10:05 nippur72

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.

nippur72 avatar May 10 '15 11:05 nippur72

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.

nippur72 avatar May 11 '15 10:05 nippur72

Also:

  • I'm using Round in place of Floor
  • Fixed the impossibility to scroll to last line (by dragging scroll bar) if not a multiple of line height

nippur72 avatar May 11 '15 15:05 nippur72

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.

nippur72 avatar May 11 '15 15:05 nippur72