Bug 155771 - [Viewers] With Compare with Each Other, unwanted scroll to top
Summary: [Viewers] With Compare with Each Other, unwanted scroll to top
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Compare (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.3 M4   Edit
Assignee: Platform-Compare-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 140122 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-08-31 03:34 EDT by Max Gilead CLA
Modified: 2007-06-05 15:28 EDT (History)
3 users (show)

See Also:


Attachments
Should be applied to org.eclipse.compare; fixes this bug (1.00 KB, patch)
2006-11-15 23:35 EST, Andrey Tarantsov CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Max Gilead CLA 2006-08-31 03:34:28 EDT
Cursor jumps to the top when modifying files in compare editor
1. Compare two files
2. Scroll down a bit
3. Copy something from left editor
4. Paste in right editor
5. Click on the left editor (intending to copy another piece of text)
6. Editors are scrolled to the top of first different block

It's mighty irritating when user needs to copy a lot of strings between editors and they're somewhere down the file.
Comment 1 Michael Valenta CLA 2006-10-20 11:01:47 EDT
I've had a look at this and it appears that the unwanted scroll to the top only happens the first time. It is due to the use of synchronized scrolling and is triggered by a viewport event from the source viewer. It only happens when both sides are editaqble which is unique to Comapre with Each Other. Given the complexity of the problem and the fact that it is an isolated case, I don't feel that we need to address this in 3.3.

One thing that would help is to make the Synchronized Scrolling an option you can turn on and off in the merge viewer. It is currently only settale in the global preference page.
Comment 2 Max Gilead CLA 2006-10-30 14:27:23 EST
Isn't it related to bugs #84173, #92255 and #140122 (they all look like dupes)?
Comment 3 Michael Valenta CLA 2006-10-30 15:04:34 EST
*** Bug 92255 has been marked as a duplicate of this bug. ***
Comment 4 Michael Valenta CLA 2006-10-30 15:05:21 EST
*** Bug 140122 has been marked as a duplicate of this bug. ***
Comment 5 Andrey Tarantsov CLA 2006-11-14 10:59:33 EST
I think I know the source of this bug. I have copied the compare UI code for use in another project and fixed the bug there. I do not know if this resolution really applies to the original Eclipse compare editor, but I believe so.

The source of the problem: In synchronized scrolling mode the source viewers' scrollbars are hidden and a common simulated scrollbar is shown instead. After the loading of the editor, this common scroll bar displays the correct position. However the scrollbars of each StyledText widget (which, being hidden, are still used by the widget to determine scroll offsets) have incorrect offsets. After you do any scrolling, the internal hidden scrollbar is updated with the correct position and is kept up to date thereafter.

How to verify the source of the problem. If you make the StyledText's scrollbars visible (resulting in 3 scrollbars displayed -- two viewers' and one common), you will see the fact of incorrect positioning with your own eyes.

Fixing. In TextMergeViewer, there is a method called updateContent. At the very end of it, there are such lines:

if (selectDiff != null)
	setCurrentDiff(selectDiff, true);
else
	selectFirstDiff();

If you invoke them via Display.asyncExec, the problem goes away. In my code, I've replaced them with:

final Diff selectedDiff = selectDiff;
getControl().getDisplay().asyncExec(new Runnable() {
	public void run() {
		if (selectedDiff != null)
			setCurrentDiff(selectedDiff, true);
		else
			selectFirstDiff();
	}
});

Again, I have not verified this resolution, it just works for me with my private copy of Eclipse compare UI.

Andrey Tarantsov, xored software, Inc. <andreyvit@xored.com>
Comment 6 Andrey Tarantsov CLA 2006-11-15 23:35:52 EST
Created attachment 53971 [details]
Should be applied to org.eclipse.compare; fixes this bug

Adding a patch for this bug. Checked with 3_2_mainenance brach. Patched jars for 3.2 and 3.2.1 are available from my page at http://andreyvit.googlepages.com/eclipsecompareuipatch.
Comment 7 Andrey Tarantsov CLA 2006-11-15 23:43:59 EST
...Have reread the bug description more thoughtfully. The initial reproducing steps are strange, but the title ("With Compare with Each Other, unwanted scroll to top") is just what I intended. So, to be sure, the exact steps to reproduce the fixed bug are:

1. Compare two files several screens long and with the first difference being somewhere in the middle
2. Click on one of the editors to activate it
3. Use your mouse wheen to scroll it in any direction

The editor immediately scrolls to the top, though it was expected to scroll just a few lines forward or backward.
Comment 8 Aaron Digulla CLA 2006-11-16 03:47:23 EST
You're right, the first bug report seems something else but your patch fixes at least my Bug 140122 :-)
Comment 9 Andrey Tarantsov CLA 2006-11-16 06:26:49 EST
Yes, but other bugs that describe exactly what I fixed, including your 140122, were marked as duplicates of this one. So I consider this bug to include those.
Comment 10 Aaron Digulla CLA 2006-11-16 08:20:38 EST
Max, can you confirm that this fix in fact solves your original problem, too?
Comment 11 Michael Valenta CLA 2006-11-16 09:28:12 EST
Sorry for taking so long to comment on this but I've been swamped lately. First of all, I want to say thank you for providing patches for this. We appreciate the effort. However, I have a couple of issues with the provided patch. First of all, it is against the 3.2 maintenance branch. The code in HEAD has changed considerably since then. As a matter of fact, I have tried the scenario in 3.3 and it no longer fails (using build  I20061114-1636). I suspect it was fixed when we added code that would maintain the current selection and position if the viewer was being refreshed. Given the subtle nature of this bug, I would be helpful if those copied on this bug could verify this for all the scenarios where the problem has appeared.

The other issue I have with the patch is that it fixed a problem by essentially delaying when a piece of code was performed. The problem is that delaying that code may have introduced other problems that would have been equally subtle.
Comment 12 Max Gilead CLA 2006-11-16 11:42:25 EST
I checked this bug with I20061102-1715 and I20061114-1636 and I confirm it's fixed. However the suspicion that this bug is the same as the ones marked as duplicates was wrong -- I tried two scenarios: synchronize file with CVS repository and compare two disk files and view is still scrolled to the top in both cases.
Comment 13 Michael Valenta CLA 2006-11-16 12:57:40 EST
You are right. In the end, there were two bugs. However, initially, the symptoms were very similar and hence the marking as a duplicate. In 3.3, both problems appear to be fixed. However, if you find a case that still fails, I would ask you to enter a separate bug just so the confusion around the already entered bugs is avoided (although it would still be good to reference these bugs for completeness).
Comment 14 Max Gilead CLA 2006-11-16 16:28:50 EST
OK, but couldn't these other bugs just be unmarked as duplicates? It would be simpler and there would be less bugs.
Comment 15 Michael Valenta CLA 2006-11-16 16:44:11 EST
Given that both bugs are fixed, I don't see the benefit in changing any of the resolutions at this point.