Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 494565 - [GTK] Snippet243 doesn't work because Text#insert(String) modifies topIndex
Summary: [GTK] Snippet243 doesn't work because Text#insert(String) modifies topIndex
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.8 M1   Edit
Assignee: Eric Williams CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-25 11:47 EDT by Markus Keller CLA
Modified: 2017-08-01 13:06 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2016-05-25 11:47:08 EDT
Ubuntu 14.04, GTK 2 and GTK 3.10.8. Works fine on Windows 7.

Snippet243 doesn't work on GTK because Text#insert(String) modifies the topIndex 

Steps:
- launch Snippet243
- enter text:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- press ArrowUp until the line "4" becomes the top visible line
- modify line "6" to "66"
=> expected: right text field should show line "4" on top
=> was: line "66" on top

After bug 487467, get/setTopIndex(..) seem to work fine, but reseting the topIndex to the modified line on insert(..) is not OK.
Comment 1 Eric Williams CLA 2016-05-25 11:55:35 EDT
This is a regression from bug 487467 that was actually fixed morning. It will land in RC3.

*** This bug has been marked as a duplicate of bug 487467 ***
Comment 2 Markus Keller CLA 2016-05-25 12:01:22 EDT
No, still happens with master: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=83f68458d1ae8ca986e87c6cf49dcb5c4bf9ba65

Looks like a regression from bug 466314.

The changes from
  gtk_text_view_scroll_mark_onscreen()
to
  gtk_text_view_scroll_to_mark(..., true, 0, 0)
were wrong, since they unconditionally set the topIndex to the line that contains the mark.
Comment 3 Eric Williams CLA 2016-05-25 12:08:55 EDT
I stand corrected: will investigate.
Comment 4 Eric Williams CLA 2016-05-25 16:05:50 EDT
(In reply to Markus Keller from comment #2)
> Looks like a regression from bug 466314.

So I'm not actually sure this is the case. If I go back past the commit for this fix, the same behavior is exhibited. I.e. doing:

> Steps:
> - launch Snippet243
> - enter text:
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> 12
> 13
> 14
> 15
> - press ArrowUp until the line "4" becomes the top visible line
> - modify line "6" to "66"
> => expected: right text field should show line "4" on top
> => was: line "66" on top

Yields the bug: 66 ends up on top as well in the second text box. This doesn't happen on GTK2, though. I have a suspicion that this has something to do with row validation in GTK3.
Comment 5 Eric Williams CLA 2016-06-06 08:58:39 EDT
This issue is reproducible on Mars, as well as Mars.1/2.
Comment 6 Arun Thondapu CLA 2016-08-23 04:18:10 EDT
Eric, are you planning to work on this for 4.6.1? I'm changing the target to 4.6.2, please reset if necessary.
Comment 7 Eric Williams CLA 2016-08-23 18:40:13 EDT
(In reply to Arun Thondapu from comment #6)
> Eric, are you planning to work on this for 4.6.1? I'm changing the target to
> 4.6.2, please reset if necessary.

Correct -- in fact, this is still an issue for 4.7 so I'm going to set that as the milestone. This bug has been reproducible for awhile, back to Mars.
Comment 8 Alexander Kurtakov CLA 2017-05-23 03:15:42 EDT
Move out of 4.7.
Comment 9 Eric Williams CLA 2017-06-13 15:25:33 EDT
Update: I am seeing this bug on GTK2 as well now. Not sure what has changed in the last year or so but GTK2 is affected as well.

On GTK3 I am also seeing the following behaviour: inserting the 6 causes the bug to happen. Inserting another 6 causes second viewer to scroll up to the four. Typing another 6 causes the viewer to scroll down to the 6. This alternates with every additional 6 inserted.
Comment 10 Eric Williams CLA 2017-06-15 17:04:01 EDT
In Snippet243 there is a SWT.Verify handler that calls three methods:

-set/getTopIndex
-setSelection(int, int)
-insert()

insert() is responsible for this bug. Everything else seems to be working as intended.

insert() is calling gtk_text_view_scroll_to_mark() for non SWT.SINGLE Text widgets. On GTK the way this works is that the GtkTextMark is scrolled to and placed at the top of the viewer. This is what is resetting the topIndex (what I said in comment 4 was incorrect).

Now technically the Text.insert() API says nothing about scrolling at all: merely that the text at the selection should change. Intuitively it seems that inserting text at the selection merits the viewer being scrolled. For example: if a user manually selected text, scrolled the viewer so that the selection is not visible and then typed something, the viewer would scroll back to the newly inserted text automatically.

Furthermore in bug 197785, there is behaviour on other platforms WRT scrolling that is not API: for example 197785#c1 states that Win32 scrolls at the end of the setSelection() call. To me this is also intuitive, just as the case I mentioned before with Text.insert(). On GTK we now have this behaviour as well.

This does not technically break the topIndex API, as set/getTopIndex are still functioning as expected.

I don't really see a clear way to fix this bug. GTK offers no way to check if a GtkTextMark is visible in the viewer, which would make fixing this bug easier. I tried some different approaches to get this to work but nothing works 100% without some unexpected consequences. I also thinking reverting the fix for bug 466314 is a bad idea, since that bug seems more sinister than this one.

Maybe we could modify the Javadocs for set/getTopIndex? Something like "On some platforms, the topIndex is modified by selecting/deleting/inserting text"?

Thoughts?
Comment 11 Markus Keller CLA 2017-06-15 18:07:49 EDT
Making the modified line / selection visible if it was scrolled out of view is fine. But always scrolling the modified line to the top of the text widget is not OK.
Comment 12 Eric Williams CLA 2017-06-29 17:00:04 EDT
(In reply to Markus Keller from comment #11)
> Making the modified line / selection visible if it was scrolled out of view
> is fine. But always scrolling the modified line to the top of the text
> widget is not OK.

That's a fair point. I have submitted a patch for this bug with a different approach, ready for you to review.
Comment 14 Eric Williams CLA 2017-07-17 14:35:59 EDT
(In reply to Eclipse Genie from comment #13)
> Gerrit change https://git.eclipse.org/r/100405 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=6e81aaed66307e9b6e37e31d91f2740f53add5b4

Patch is in master now. Thanks Markus for bringing attention to this issue.