Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335902 - [Keybindings] Java code formatter (shift+ctrl+F) formats wrong file (build.xml instead of java file)
Summary: [Keybindings] Java code formatter (shift+ctrl+F) formats wrong file (build.xm...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-31 16:04 EST by Sergey Bushkov CLA
Modified: 2019-09-24 13:51 EDT (History)
5 users (show)

See Also:


Attachments
screenshot - wrong file changed by formatter (69.84 KB, image/png)
2011-01-31 16:06 EST, Sergey Bushkov CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Bushkov CLA 2011-01-31 16:04:15 EST
Build Identifier: 3.6.1 M20100909-0800

When java files and build.xml files are opened in the eclipse workspace, and a java editor is active, "ctrl+shift+F" formats one of build.xml files instead of the java file.

Reproducible: Always

Steps to Reproduce:
A project contains a java file, and the ant build.xml file.

1) Open the java file in the editor;
2) Open the build.xml file in the editor; edit it; save;
3) Go back to the java file, edit it, save;

At this point, both editors are saved (no '*' dirty mark).

4) Press 'Shift+Ctrl+F' in the Java editor. The java file is not changed, but the build.xml file is formatted instead (text becomes formatted, and the 'dirty' mark appears).

At the same time, "Format" action from the main menu works correctly, and the "Format" action from the popup menu works correctly, too.
Comment 1 Sergey Bushkov CLA 2011-01-31 16:06:36 EST
Created attachment 188007 [details]
screenshot - wrong file changed by formatter
Comment 2 Dani Megert CLA 2011-02-01 03:22:54 EST
Works fine on Windows XP but is indeed broken on Linux (3.6.1 and 3.7 M5).
This looks like a platform dependent bug in the command/handler service.

Paul, can you take a look?
Comment 3 Paul Webster CLA 2011-02-01 10:29:31 EST
Hmmm, I don't even get the KeyDown for the F on linux.  Now to find out where it went.

PW
Comment 4 Dani Megert CLA 2011-02-01 10:37:50 EST
(In reply to comment #3)
> Hmmm, I don't even get the KeyDown for the F on linux.  Now to find out where
> it went.
But you see that it formats the XML file?
Comment 5 Dani Megert CLA 2011-02-01 10:51:17 EST
Just as a background: Ctrl+Shift+F does not work on some GTKs. Therefore we defined an additional binding. Here's how it looks like:

      <key
            sequence="M1+M2+F"
            contextId="org.eclipse.jdt.ui.javaEditorScope"
            commandId="org.eclipse.jdt.ui.edit.text.java.format"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
      <!-- alternative for some gtk input modes -->
      <key
            platform="gtk"
            sequence="ESC CTRL+F"
            contextId="org.eclipse.jdt.ui.javaEditorScope"
            commandId="org.eclipse.jdt.ui.edit.text.java.format"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>

And Ant (XML) does this:
      <key
            sequence="M1+M2+F"
            contextId="org.eclipse.ant.ui.AntEditorScope"
            commandId="org.eclipse.jdt.ui.edit.text.java.format"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
      <!-- alternative for some gtk input modes -->
      <key
            platform="gtk"
            sequence="ESC CTRL+F"
            contextId="org.eclipse.ant.ui.AntEditorScope"
            commandId="org.eclipse.jdt.ui.edit.text.java.format"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>

Of course this doesn't explain why the command is triggered in the non-active editor.
Comment 6 Paul Webster CLA 2011-02-01 10:55:07 EST
Yes, I can reproduce reliably.

On my linux (RHEL6 based) I do not get the 'F' KeyDown event ... it's not even being processed in Widget.gtk_key_press_event(*)

PW
Comment 7 Paul Webster CLA 2011-02-01 11:11:20 EST
CTRL+SHIFT+F is turned into a menu event, which is why I don't see a key event.

TextOperationAction$1.run() line: 131	
BusyIndicator.showWhile(Display, Runnable) line: 70	
TextOperationAction.run() line: 129	
RetargetTextEditorAction.run() line: 237	
RetargetTextEditorAction(Action).runWithEvent(Event) line: 498	
ActionContributionItem.handleWidgetSelection(Event, boolean) line: 584	
ActionContributionItem.access$2(ActionContributionItem, Event, boolean) line: 501	
ActionContributionItem$5.handleEvent(Event) line: 411	
EventTable.sendEvent(Event) line: 84	
MenuItem(Widget).sendEvent(Event) line: 1258	
Display.runDeferredEvents() line: 3540	
Display.readAndDispatch() line: 3161
Comment 8 Paul Webster CLA 2011-02-01 11:59:46 EST
OK, ready for this:

1) on GTK+ we set accelerators on the MenuItems for "Ctrl+Shift+[0-9A-FU]" as a workaround for bug 42009

2) when we open the ant build file, it creates one of these MenuItems at the bottom of the Edit menu

3) when we switch to the Java editor, that menu item still exists (because we won't update the Edit MenuManager unless the user opens that menu).

4) CTRL+SHIFT+F goes to the menu item, which is still tied to the ant editor, and voila.

Opening and closing the Edit menu before CTRL+SHIFT+F allows it to work with the java editor (this is not a workaround, merely an observation).

PW
Comment 9 Paul Webster CLA 2011-02-01 12:20:11 EST
Felipe, do we not have to guard against "Ctrl+Shift+[0-9A-FU]" anymore in GTK+?

If I take out my accelerator hack from org.eclipse.jface.action.ActionContributionItem.update(String):860 CTRL+SHIFT+F then works correctly in both ant and java editors.

How can we find out what version of GTK that 0-9A-F became no longer a problem?

PW
Comment 10 Sergey Bushkov CLA 2011-02-01 15:17:45 EST
(In reply to comment #9)

Not sure about [0-9][A-F], maybe it's safe to remove the guard; but Shift+Ctrl+U brings the underline "U", and waits for digits.

For example, (Shift+Ctrl+U, 2, 1, Enter) inserts "!" both in eclipse java editor and gedit and gnome-terminal.
Comment 11 Felipe Heidrich CLA 2011-02-01 15:39:11 EST
(In reply to comment #9)
> Felipe, do we not have to guard against "Ctrl+Shift+[0-9A-FU]" anymore in GTK+?

Not sure, see:
http://hpux.connect.org.uk/hppd/hpux/Gtk/Development/gtk+2-2.22.1/readme.html

It reads:
Release notes for 2.10
======================

* The hexadecimal Unicode input feature has been reworked. It no longer
  blocks the use of the sixteen Ctrl-Shift-<hex digit> key sequences. Now
  it only uses Ctrl-Shift-u.

-----------
I can confirm on my machine that Ctrl+Shift+[0-9A-F] does nothing.
I have to hold Ctrl+Shift, hit U, then enter the hex for the code point I want.
Comment 12 Lars Vogel CLA 2019-09-24 13:51:40 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.