Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 348792

Summary: [client] can't esc key assist panel when the editor has focus
Product: [ECD] Orion Reporter: Susan McCourt <susan>
Component: ClientAssignee: Susan McCourt <susan>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe
Version: 0.2Flags: eclipse.felipe: review+
Target Milestone: 0.2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
diff none

Description Susan McCourt CLA 2011-06-08 15:08:11 EDT
This was actually the original symptom for bug 347875.  I thought that fixing this bug would fix this symptom, so I never opened a bug for the symptom.

Turns out...even if editor doesn't stop propagation of Esc, the document won't get the keystroke since the editor is in an iframe.

So indeed I need to hook esc in the editor as an additional mode, and dismiss key assist panel if it is up.
Comment 1 Susan McCourt CLA 2011-06-08 16:10:04 EDT
I can't simply have the globalCommands register an esc binding, since the editorFeatures already does so.  Probably can accomplish this by having the key binding factory have a parameter that editor could use for forwarding esc key if no active modes implement it.
Comment 2 Susan McCourt CLA 2011-06-08 20:11:37 EDT
Created attachment 197658 [details]
diff
Comment 3 Susan McCourt CLA 2011-06-08 20:26:58 EDT
Felipe, can you please review?
You can either use the provided diff file, or you can get the code from branch "bug348792" in the remote git repo.

I probably need to explain the fix, as no one else has really had to know how the editor.js handles Esc.  We have many external objects that need to know about the same keystrokes (such as esc, enter, lineup, linedown).  Since the textView doesn't manage multiple modal key handlers, we create an array of "keyModes" inside the editor for managing this.

- For modal keys like Esc, Enter, LineUp, LineDown, etc. the editor checks the keyMode array to see which mode is active.  It then sends that keyMode messages like "cancel," "lineUp," "lineDown," "enter" etc.
- The various factories that are modal (contentAssist, keyBindingFactory) add themselves to the keyMode array.

The solution needs to be able to set up another one of these external modes and then provide functionality in globalCommands so that any globalCommand which needs Esc functionality can hook into it.  So the solution is:

- in setup.js we create something called escHandler whose job is to keep track of anyone else who would like to handle escape from the editor.  This handler keeps a list of handlers that need to know about escape. 
- this escHandler adds itself to editor keyModes so that it can participate in the modal keyStokes
- when asked isActive, this handler checks to see if any of its handlers are active
- when sent cancel, this handler sends cancel to all external handlers and then lets the editor know if it was handled by any of them
- this handler ignores all of the other modal keystrokes (answering false to indicate it doesn't handle them)
- our escHandler is passed to globalCommands, called "escapeProvider" and then globalCommands makes its own escape handler for keyAssist and adds it to this provider's esc handlers
- I also added another handler inside setup.js for the search popup.  (This will be needed in bug 341395 but it made sense to do it here.)

So...to test that it works:
- the key assist panel (Ctrl+Shift+?) should now disappear when you push cancel from the editor
- likewise the global search panel (Ctrl+H) will do the same
- if both panels are up, esc will cancel both of them (intentional)
- if the editor is in some other mode (like Ctrl+J incremental search), that mode will handle Esc as long as it is alive, and when it is canceled, the Esc would go back to any open popups.

Please ping me if this explanation is not good.
Comment 4 Susan McCourt CLA 2011-06-08 21:34:41 EDT
opened bug 348823 to discuss how we might do better and provide explicit API in this area.
Comment 5 Susan McCourt CLA 2011-06-09 16:12:36 EDT
pushed fix