This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 391626 - [Compatibility] e4 does not implement the post-selection concept
Summary: [Compatibility] e4 does not implement the post-selection concept
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.2.2   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
: 386640 387113 397510 (view as bug list)
Depends on:
Blocks: 385272
  Show dependency tree
 
Reported: 2012-10-11 01:26 EDT by Toshihiro Izumi CLA
Modified: 2013-03-11 05:03 EDT (History)
10 users (show)

See Also:
pwebster: review+


Attachments
test plug-in project (8.24 KB, application/x-zip-compressed)
2012-10-11 16:28 EDT, Nitin Dahyabhai CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Toshihiro Izumi CLA 2012-10-11 01:26:41 EDT
Steps to Reproduce:
1. Create a simple html file
  1: <html>
  2:   <head>
  3:   </head>
  4:   <body>
  5:     <p>Text</p>
... repeat above line 100 times
105:   </body>
106: </html>
2. Go to line 105
3. Press and hold Shift+UpArrow

The outline scrolls hard and hard(moving up and down). The cursor runs without block-seletion(region highlighted), and then selecting lines takes a few seconds per line.

Turning off Link-with-Editor is the only workaround for now.

This problem occurs on
Eclipse SDK    4.2.1.M20120914-1800
Eclipse Web Developer Tools    3.4.1.v201208170345-7O7MFsPEMkBJz0wtb-ccsarPSceUIHO9iKk6XVPV

Not occurs on
Eclipse SDK    3.8.1.M20120914-1540
Eclipse Web Developer Tools    3.4.1.v201208170345-7O7MFsPEMkBJz0wtb-ccsarPSceUIHO9iKk6XVPV

Each WTP3.4.1 is installed from juno repository and they are same on 4.2.1 and 3.8.1 of course.(I confirmed it with fc/b command also)
Comment 1 Toshihiro Izumi CLA 2012-10-11 01:27:24 EDT
As far as I can inspect,
org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage.PostSelectionServiceListener.selectionChanged(IWorkbenchPart, ISelection)
is called per a line while key-repeating.(I confirmed 'per a line' by inserting sysout selection arg) It causes updating outline every time.
On 3.8.1, it is called once at the end of key-repeating. Outline is updated once at the end.

Stacktrace on 4.2.1: Suspended at first press-and-hold keys.(maybe before starting key-repeating)

Thread [main] (Suspended (breakpoint at line 162 in ConfigurableContentOutlinePage$PostSelectionServiceListener))
    owns: SelectionAggregator$4  (id=200)
    ConfigurableContentOutlinePage$PostSelectionServiceListener.selectionChanged(IWorkbenchPart, ISelection) line: 162
    SelectionService.notifyListeners(String, IWorkbenchPart, ISelection) line: 140
    SelectionService.access$3(SelectionService, String, IWorkbenchPart, ISelection) line: 137
    SelectionService$1.selectionChanged(MPart, Object) line: 72
    SelectionAggregator$2.run() line: 111
    SafeRunner.run(ISafeRunnable) line: 42
    SelectionAggregator.notifyListeners(MPart, Object) line: 109
    SelectionAggregator.access$4(SelectionAggregator, MPart, Object) line: 106
    SelectionAggregator$4$1.run() line: 163
    SelectionAggregator$4(RunAndTrack).runExternalCode(Runnable) line: 53
    SelectionAggregator$4.changed(IEclipseContext) line: 161
    TrackableComputationExt.update(ContextChangeEvent) line: 110
    EclipseContext.processScheduled(Set<Scheduled>) line: 318
    EclipseContext.set(String, Object) line: 332
    SelectionServiceImpl.setSelection(Object) line: 30
    CompatibilityEditor(CompatibilityPart).selectionChanged(SelectionChangedEvent) line: 420
    StructuredTextEditor$4.run() line: 591
    SafeRunner.run(ISafeRunnable) line: 42
    StructuredTextEditor$StructuredSelectionProvider.fireSelectionChanged(SelectionChangedEvent, ListenerList) line: 589
    StructuredTextEditor$StructuredSelectionProvider.handleSelectionChanged(SelectionChangedEvent) line: 681
    StructuredTextEditor$2.selectionChanged(SelectionChangedEvent) line: 557
    Viewer$2.run() line: 164
    SafeRunner.run(ISafeRunnable) line: 42
    JFaceUtil$1.run(ISafeRunnable) line: 49
    SafeRunnable.run(ISafeRunnable) line: 175
    StructuredTextViewer(Viewer).fireSelectionChanged(SelectionChangedEvent) line: 162
    StructuredTextViewer(TextViewer).fireSelectionChanged(int, int) line: 2738
    StructuredTextViewer(TextViewer).selectionChanged(int, int) line: 2717
    TextViewer$4.widgetSelected(SelectionEvent) line: 1836
    TypedListener.handleEvent(Event) line: 248
    EventTable.sendEvent(Event) line: 84
    StyledText(Widget).sendEvent(Event) line: 1053
    StyledText(Widget).sendEvent(int, Event, boolean) line: 1077
    StyledText(Widget).sendEvent(int, Event) line: 1062
    StyledText(Widget).notifyListeners(int, Event) line: 774
    StyledText.sendSelectionEvent() line: 8048
    StyledText.doSelection(int) line: 3219
    StyledText.doLineUp(boolean) line: 2703
    StyledText.doSelectionLineUp() line: 3296
    StyledText.invokeAction(int) line: 6921
    StyledText.handleKey(Event) line: 5911
    StyledText.handleKeyDown(Event) line: 5937
    StyledText$7.handleEvent(Event) line: 5629
    EventTable.sendEvent(Event) line: 84
    StyledText(Widget).sendEvent(Event) line: 1053
    StyledText(Widget).sendEvent(int, Event, boolean) line: 1077
    StyledText(Widget).sendEvent(int, Event) line: 1062
    StyledText(Widget).sendKeyEvent(int, int, int, int, Event) line: 1104
    StyledText(Widget).sendKeyEvent(int, int, int, int) line: 1100
    StyledText(Widget).wmKeyDown(int, int, int) line: 1823
    StyledText(Control).WM_KEYDOWN(int, int) line: 4892
    StyledText(Control).windowProc(int, int, int, int) line: 4560
    StyledText(Canvas).windowProc(int, int, int, int) line: 341
    Display.windowProc(int, int, int, int) line: 4976
    OS.DispatchMessageW(MSG) line: not available [native method]
    OS.DispatchMessage(MSG) line: 2546
    Display.readAndDispatch() line: 3756
    PartRenderingEngine$9.run() line: 1029
    Realm.runWithDefault(Realm, Runnable) line: 332
    PartRenderingEngine.run(MApplicationElement, IEclipseContext) line: 923
    E4Workbench.createAndRunUI(MApplicationElement) line: 86
    Workbench$5.run() line: 588
    Realm.runWithDefault(Realm, Runnable) line: 332
    Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 543
    PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149
    IDEApplication.start(IApplicationContext) line: 124
    EclipseAppHandle.run(Object) line: 196
    EclipseAppLauncher.runApplication(Object) line: 110
    EclipseAppLauncher.start(Object) line: 79
    EclipseStarter.run(Object) line: 353
    EclipseStarter.run(String[], Runnable) line: 180
    NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
    NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
    DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
    Method.invoke(Object, Object...) line: not available
    Main.invokeFramework(String[], URL[]) line: 629
    Main.basicRun(String[]) line: 584
    Main.run(String[]) line: 1438
    Main.main(String[]) line: 1414

Stacktrace on 3.8.1: Suspended after stopping pressing keys.

Thread [main] (Suspended (breakpoint at line 162 in ConfigurableContentOutlinePage$PostSelectionServiceListener))
    ConfigurableContentOutlinePage$PostSelectionServiceListener.selectionChanged(IWorkbenchPart, ISelection) line: 162
    WindowSelectionService(AbstractSelectionService).firePostSelection(IWorkbenchPart, ISelection) line: 179
    AbstractSelectionService$2.selectionChanged(SelectionChangedEvent) line: 71
    StructuredTextEditor$4.run() line: 591
    SafeRunner.run(ISafeRunnable) line: 42
    StructuredTextEditor$StructuredSelectionProvider.fireSelectionChanged(SelectionChangedEvent, ListenerList) line: 589
    StructuredTextEditor$StructuredSelectionProvider.handlePostSelectionChanged(SelectionChangedEvent) line: 670
    StructuredTextEditor$3.selectionChanged(SelectionChangedEvent) line: 563
    StructuredTextViewer(TextViewer).firePostSelectionChanged(SelectionChangedEvent) line: 2755
    StructuredTextViewer(TextViewer).firePostSelectionChanged(int, int) line: 2703
    TextViewer$5.run() line: 2682
    Display.runTimer(int) line: 4270
    Display.messageProc(int, int, int, int) line: 3357
    OS.DispatchMessageW(MSG) line: not available [native method]
    OS.DispatchMessage(MSG) line: 2546
    Display.readAndDispatch() line: 3756
    Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2701
    Workbench.runUI() line: 2665
    Workbench.access$4(Workbench) line: 2499
    Workbench$7.run() line: 679
    Realm.runWithDefault(Realm, Runnable) line: 332
    Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 668
    PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149
    IDEApplication.start(IApplicationContext) line: 124
    EclipseAppHandle.run(Object) line: 196
    EclipseAppLauncher.runApplication(Object) line: 110
    EclipseAppLauncher.start(Object) line: 79
    EclipseStarter.run(Object) line: 353
    EclipseStarter.run(String[], Runnable) line: 180
    NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
    NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
    DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
    Method.invoke(Object, Object...) line: not available
    Main.invokeFramework(String[], URL[]) line: 629
    Main.basicRun(String[]) line: 584
    Main.run(String[]) line: 1438
    Main.main(String[]) line: 1414
Comment 2 Nitin Dahyabhai CLA 2012-10-11 16:28:45 EDT
Created attachment 222201 [details]
test plug-in project
Comment 3 Nitin Dahyabhai CLA 2012-10-11 16:30:21 EDT
From the trace in comment 1, our selection provider, whenever it gets a plain *non* post selection notification from the source viewer ends up triggering a selection service post selection immediately.  It's demonstrable with the attached view and the regular Text Editor that a *post selection* notification occurs on each change to the existing selection in the source viewer.  IIRC, in 3.8 if you changed the length of the selection, selection notifications would fire immediately as well, but listeners solely listening for post selection wouldn't get notified.
Comment 4 Dani Megert CLA 2012-10-12 02:17:58 EDT
I'll take a look whether this is a regression. Note that there are some actions that always (since day one) issue a selection change directly. We won't change that part.
Comment 5 Nitin Dahyabhai CLA 2012-10-12 11:48:45 EDT
(In reply to comment #4)
> I'll take a look whether this is a regression. Note that there are some
> actions that always (since day one) issue a selection change directly. We
> won't change that part.

Oh I have no disagreement on that, only that my post selection listener is getting more than post selection notifications.
Comment 6 Dani Megert CLA 2012-10-16 09:59:58 EDT
This is pretty ugly: the concept of post-selection listeners/events is not implemented in e4 at all! See org.eclipse.ui.internal.e4.compatibility.SelectionService.addPostSelectionListener(ISelectionListener):

	public void addPostSelectionListener(ISelectionListener listener) {
		// TODO compat addPostSelectionListener
		addSelectionListener(listener);
	}

In addition, the CompatibilityPart also looks like it needs work to support this.


IMPORTANT NOTE: All parts that listen to post-selection events are affected by this bug. Such listeners usually use the post-selection mechanism because they do more work than is done on a normal selection change event. This is now doomed in e4 because they are notified on every selection change, e.g. when keeping the down arrow key pressed in the 'Package Explorer' they are swamped with events.
Comment 7 Dani Megert CLA 2012-10-16 10:00:49 EDT
This should be fixed for 4.2.2.
Comment 8 Dani Megert CLA 2012-10-18 07:45:18 EDT
This is really serious. I'll try to come up with an initial patch.
Comment 9 Dani Megert CLA 2012-10-18 08:36:47 EDT
I've pushed a possible fix to the following topic branch:
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/log/?h=dmegert/bug_39162

Paul and/or Eric please thoroughly review this proposed fix (I'm not yet 100% familiar with all the e4 stuff). Things to specially check:

SelectionAggregator.track(MPart)
- Not sure whether it is the correct place to reset OUT_POST_SELECTION
  with context.set(OUT_POST_SELECTION, null) here. For sure it needs to be
  removed form that context otherwise it remains in there.

org.eclipse.e4.ui.workbench.modeling.ESelectionService
- Has new methods. I assume this is OK since there's no other subclass and there
  is no official API for e4 yet. If not, we have to add an extension interface
  which will unfortunately make the code more complicated.

- I was not able to the test the post-selection stuff against a pure e4 part
  since AFAIK there's none yet in the SDK.
Comment 10 Dani Megert CLA 2012-10-18 08:41:21 EDT
To test this, a simpler way than using the attached test plug-in, is to add the following code to a view (e.g. into PackageExplorerPart.createPartControl(Composite) and make sure it is open in the target/test workspace):

getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(
    new ISelectionListener() {
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            System.out.println("received post-selection");
        }
    }
);
Comment 11 Dani Megert CLA 2012-10-18 08:47:39 EDT
(In reply to comment #9)
> I've pushed a possible fix to the following topic branch:
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/log/?h=dmegert/
> bug_39162

Of course it's dmegert/bug_391626 i.e.
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/log/?h=dmegert/bug_391626
Comment 12 Paul Webster CLA 2012-10-19 11:12:47 EDT
(In reply to comment #11)
> 
> Of course it's dmegert/bug_391626 i.e.
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/log/?h=dmegert/
> bug_391626

The initial cut looks reasonable, but I'm getting the post selection event before the selection event sometimes.

I'm investigating.

PW
Comment 13 Dani Megert CLA 2012-10-20 02:26:22 EDT
(In reply to comment #12)
> (In reply to comment #11)
> > 
> > Of course it's dmegert/bug_391626 i.e.
> > http://git.eclipse.org/c/platform/eclipse.platform.ui.git/log/?h=dmegert/
> > bug_391626
> 
> The initial cut looks reasonable, but I'm getting the post selection event
> before the selection event sometimes.

That would be strange but might not necessarily be a bug in the framework but the part that sends them out. If you have steps, then we should also try them on 3.8.1.
Comment 14 Dani Megert CLA 2012-10-24 10:19:12 EDT
*** Bug 386640 has been marked as a duplicate of this bug. ***
Comment 15 Paul Webster CLA 2012-10-24 16:31:04 EDT
I'm down to getting one extra selection event for the correct postSelection event.

I'm just investigating this one last problem.

PW
Comment 16 Dani Megert CLA 2012-10-25 03:46:37 EDT
(In reply to comment #15)
> I'm down to getting one extra selection event for the correct postSelection
> event.
> 
> I'm just investigating this one last problem.
> 
> PW

Great. The second event might not be related to the patch but be bug 387113.
Comment 17 Paul Webster CLA 2012-10-25 09:28:36 EDT
I've released this to 4.2.2 and master.

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?h=R4_2_maintenance&id=9db6270b7e27a2e9eaa9328d3e9a208fdea81886

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?h=R4_2_maintenance&id=b15862f11203af2f54e6371e5ede8b2b16f89367

Thanks a lot, Dani!

It also looks like it might have fixed the "fire two selection event" problem as well.

PW
Comment 18 Dani Megert CLA 2012-10-25 10:30:25 EDT
(In reply to comment #17)
> I've released this to 4.2.2 and master.
> 
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/
> ?h=R4_2_maintenance&id=9db6270b7e27a2e9eaa9328d3e9a208fdea81886
> 
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/
> ?h=R4_2_maintenance&id=b15862f11203af2f54e6371e5ede8b2b16f89367
> 
> Thanks a lot, Dani!
> 
> It also looks like it might have fixed the "fire two selection event"
> problem as well.
> 
> PW

I just verified that the fix works and also verified that it fixes the sending of two selection events (bug 387113).
Comment 19 Dani Megert CLA 2012-10-25 10:31:19 EDT
*** Bug 387113 has been marked as a duplicate of this bug. ***
Comment 20 Dani Megert CLA 2012-10-30 08:19:23 EDT
File bug 393137 related to part activation where 2 post-selection events are fired.
Comment 21 Dani Megert CLA 2013-01-07 04:14:40 EST
*** Bug 397510 has been marked as a duplicate of this bug. ***