Bug 184255 - [projection] Editor loses keyboard focus when expanding folded region
Summary: [projection] Editor loses keyboard focus when expanding folded region
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-04-26 11:42 EDT by Markus Keller CLA
Modified: 2008-04-23 09:34 EDT (History)
1 user (show)

See Also:


Attachments
Bug Fix (868 bytes, patch)
2007-06-12 10:46 EDT, Nikolay Botev CLA
no flags Details | Diff
equivalent fix for quick diff column (857 bytes, patch)
2007-06-12 11:58 EDT, Nikolay Botev CLA
no flags Details | Diff
Updated Patch (1.37 KB, patch)
2008-02-18 05:13 EST, Nikolay Botev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2007-04-26 11:42:04 EDT
I20070424-0930

- paste to Package Explorer:

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package p;
public class C { }

- click on '+' besides the first line to expand the header comment
=> keyboard focus is lost between the editor area and the window toolbar
Comment 1 Dani Megert CLA 2007-04-26 14:48:27 EDT
Important step is to wait for the projection hover to appear before clicking on the (+).

This is in since at least 3.0.
Comment 2 Nikolay Botev CLA 2007-06-12 10:46:17 EDT
Created attachment 71021 [details]
Bug Fix

setting the SWT.NO_FOCUS flag for the annotation column canvas control does it on windows. i have no way to test on other platforms.

any reason for any of the ruler columns to be able to accept keyboard focus - accessibility or any other exotic  reason? if not, then this fix should be good
Comment 3 Dani Megert CLA 2007-06-12 10:51:40 EDT
Unfortunately the NO_FOCUS bit is only a hint (see its Javadoc) and hence we cannot expect that this works on all Platforms.
Comment 4 Nikolay Botev CLA 2007-06-12 11:58:11 EDT
Created attachment 71044 [details]
equivalent fix for quick diff column

as it turns out, clicking on the quick diff bar when an information bar is visible also takes the focus away from the editor
Comment 5 Nikolay Botev CLA 2007-06-12 12:13:24 EDT
Yes, I am aware of that, however, since this bug is only filed for Windows (OS flag), I figured I could submit my patch.

> Unfortunately the NO_FOCUS bit is only a hint (see its Javadoc) and hence we
> cannot expect that this works on all Platforms.
> 

Comment 6 Markus Keller CLA 2007-06-12 12:34:08 EDT
> as it turns out, clicking on the quick diff bar when an information bar is
> visible also takes the focus away from the editor

I can't reproduce that with I20070608-1718. When I click the quick diff bar, the editor selects the whole line (and the focus stays in the text widget).
Comment 7 Nikolay Botev CLA 2007-06-30 05:44:31 EDT
 (In reply to comment #6)
> > as it turns out, clicking on the quick diff bar when an information bar is
> > visible also takes the focus away from the editor
> 
> I can't reproduce that with I20070608-1718. When I click the quick diff bar, the
> editor selects the whole line (and the focus stays in the text widget).

OK, I investigated this and here is what I found out.
This problem is introduced by my fix to bug 40889.
The projection ruler prevents external mouse listeners from attaching to its canvas and I replicate this behavior on the line number ruler in my fix to 40899.
Apparently one of the external listeners takes care of canceling the focus event so that focus is not lost.

Maybe a better solution to this bug would be to replicate what the external mouse listener does to prevent the focus change here.
Comment 5 in bug 192222 talks about a ruler API enhancement that could end up eliminating these problems altogether.
Comment 8 Nikolay Botev CLA 2008-02-18 05:13:12 EST
Created attachment 89962 [details]
Updated Patch

Here is an updated patch, which does NOT rely on SWT.NO_FOCUS (exclusively).

Here is a very detailed description:

1) SWT_NO_FOCUS is still there because there is no reason for an annotation ruler to request focus on mouse behavior.
2) The projection ruler caused the styled widget to lose focus because the NO_FOCUS flag was missing *AND* it uses the isPropagatingMouseListener() flag to turn off external mouse listeners for the ruler, which in turn disables the AbstractTextEditor mouse listener. The AbstractTextEditor mouse listener always sets the focus to the text widget on mouse up, effectively restoring focus. I replicate this behavior by calling the focus method on the text widget on mouse up for annotation rulers with isPropagatingMouseListener() = false.
Comment 9 Dani Megert CLA 2008-02-27 03:02:19 EST
Will review during M7.
Comment 10 Dani Megert CLA 2008-04-23 09:02:50 EDT
Testing on different platforms and assessing the risk at this point I will commit the patch but only the part with NO_FOCUS (works on the platforms I tested).

I added the following credentials for you to the copyright notice:

Nikolay Botev <bono8106@hotmail.com> - [projection] Editor loses keyboard focus when expanding folded region - https://bugs.eclipse.org/bugs/show_bug.cgi?id=184255

Please speak up if there's a bug in it.
Thanks.