Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 433275 - Caret gets lost
Summary: Caret gets lost
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.4   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.4.2   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 435421
  Show dependency tree
 
Reported: 2014-04-23 04:49 EDT by Jan Koehnlein CLA
Modified: 2015-01-29 02:15 EST (History)
6 users (show)

See Also:
arunkumar.thondapu: review+


Attachments
Test Snippet (2.23 KB, text/x-java)
2014-08-25 07:17 EDT, Lakshmi P Shanmugam CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Koehnlein CLA 2014-04-23 04:49:47 EDT
In Luna, the caret in text editors often disappears on MacOSX. I can still edit but see the caret is invisible. The caret reappears after some typing / clicking.

It happens almost every time I switch between two Java editors by clicking on the tabs.

Eclipse is running on Oracle Java SDK 1.8.0, MacOSX Mavericks 10.9.2. No special themes.
Comment 1 Arun Thondapu CLA 2014-04-25 10:48:26 EDT

*** This bug has been marked as a duplicate of bug 431966 ***
Comment 2 Arun Thondapu CLA 2014-05-21 05:18:25 EDT
Bug 431966 will be used to workaround this problem in Luna. Reopening this bug to track the actual problem and fix it in a proper manner.
Comment 3 Markus Keller CLA 2014-05-21 08:16:15 EDT
(In reply to Abhishek Kishore from bug bug 431966 comment #6)
> (In reply to Abhishek Kishore from comment #5)
> >
> > Caret.setFocus() is not getting called some times, causing this issue.
> > Clicking on the tab the 2nd time does that. I'm still trying to understand
> > the flow.
> 
> Looks like this is happening because of changes made for bug 388574.
> Display.ignoreFocus is true during setFocus() on StyledText, which means
> FocusIn event on it is not being fired.

That doesn't explain yet why the problem doesn't happen when WBWRenderer#forceLayout(Shell) (bug 431966 comment 4) is not called on startup.
Comment 4 Wojciech Sudol CLA 2014-05-21 08:42:57 EDT
I would like to mention that when investigating the issue it might be worth to take a look at the bug 375576, which partially introduced the bug 348954.
Comment 5 Abhishek Kishore CLA 2014-05-27 00:25:18 EDT
(In reply to Markus Keller from comment #3)
> > 
> > Looks like this is happening because of changes made for bug 388574.
> > Display.ignoreFocus is true during setFocus() on StyledText, which means
> > FocusIn event on it is not being fired.
> 
> That doesn't explain yet why the problem doesn't happen when
> WBWRenderer#forceLayout(Shell) (bug 431966 comment 4) is not called on
> startup.

Completely different flows are leading to the setFocus() calls to StyledText in the 2 cases.
When forceLayout(Shell) is called, MElementContainer.setSelectedElement(MUIElement) on line-1034 of  org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer leads to a call to StyledText.setFocus(). Without forceLayout(Shell), AbstractPartRenderer.activate(MPart) on line-1038 calls StyledText.setFocus() eventually.

Basically, the way focus shifts across widgets is very different with forceLayout(Shell) and I haven't managed to find a connection yet.
Comment 6 Abhishek Kishore CLA 2014-05-27 02:03:39 EDT
(In reply to Abhishek Kishore from comment #5)
> 
> Completely different flows are leading to the setFocus() calls to StyledText
> in the 2 cases.
> When forceLayout(Shell) is called,
> MElementContainer.setSelectedElement(MUIElement) on line-1034 of 
> org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer leads to a call to
> StyledText.setFocus(). Without forceLayout(Shell),
> AbstractPartRenderer.activate(MPart) on line-1038 calls
> StyledText.setFocus() eventually.
> 
> Basically, the way focus shifts across widgets is very different with
> forceLayout(Shell) and I haven't managed to find a connection yet.

To be clear, all this happens when the user switches tabs in the Java editor.
Comment 7 Lakshmi P Shanmugam CLA 2014-08-18 02:25:26 EDT
link to gerrit review --> https://git.eclipse.org/r/#/c/28586/
Comment 8 Lakshmi P Shanmugam CLA 2014-08-25 07:17:48 EDT
Created attachment 246307 [details]
Test Snippet

Steps to reproduce:
1. Click on the label.
2. Text is created and resized. Focus-In on Text sent.
3. New Shell with StyledText opens (on Resize event)
StyledText doesn't get focus-in event and Text doesn't get focus-out.
Comment 9 Lakshmi P Shanmugam CLA 2014-08-25 07:32:28 EDT
Hi Abhishek,

The problem happens when focus changes happen with the Resize event handler. ignoreFocus doesn't have information on the control on which the focus changes have to be ignored. So, no focus events are sent for focus changes on any control when inside Resize handler.
Your patch uses ignoreFocusControl, which is better as it has the information on the control. But, the attached snippet fails with the patch too.
I think we can check ignoreFocusControl and based on its value ignore only focus-in or focus-out, not both. Also, its not clear, what is the use of oldIgnoreFocusControl?
Is it better to use Control.ignoreFocus?
Comment 10 Dani Megert CLA 2014-09-02 15:56:15 EDT
This is worth being looked at for 4.4.2.
Comment 11 Lakshmi P Shanmugam CLA 2014-12-29 12:34:42 EST
Pushed a patch to master to fix this -- http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=57929132178dcab4df2cb95ec4d0af0055f9ce62
Comment 13 Lakshmi P Shanmugam CLA 2015-01-27 05:34:07 EST
Verified on build: I20150126-2000
Comment 14 Lakshmi P Shanmugam CLA 2015-01-29 02:15:42 EST
Verified in build: M20150128-1000