SideBySide2: Fix up first line handling in scroll synchronizer

When a line is inserted at the start of the file the A side inserts a
padding widget above the line.  CM3 doesn't always include this widget
height in the heightAtLine() computation on the A side, causing the
files to become unaligned after scrolling down and then back up.

Special case the 0th line in the editors by assuming these will be
aligned at the very top of the page on either side and just use pixel
coordinates.

Change-Id: I91f7d8afe89fa7c22ec4dcf385d24a4a8d284421
This commit is contained in:
Shawn Pearce
2014-01-01 13:59:08 -08:00
parent 1fdcc1ea25
commit 7ba907963c

View File

@@ -99,12 +99,17 @@ class ScrollSynchronizer {
// account when calculating scrollInfo when scrolling too fast (e.g.
// throw scrolling), simply setting scrollTop to be the same doesn't
// guarantee alignment.
//
int line = src.lineAtHeight(srcTop, "local");
if (line == 0) {
// Padding for insert at start of file occurs above line 0,
// and CM3 doesn't always compute heightAtLine correctly.
return srcTop;
}
// Find a pair of lines that are aligned and near the top of
// the viewport. Use that distance to correct the Y coordinate.
int line = src.lineAtHeight(srcTop, "local");
LineMapper.AlignedPair p = mapper.align(srcSide, line);
double sy = src.heightAtLine(p.src, "local");
double dy = dst.heightAtLine(p.dst, "local");
return Math.max(0, dy + (srcTop - sy));