@@ -82,7 +82,7 @@ public class BindingTableTests {
8282 "M1+X" , ID_WINDOW , PASTE_ID , "M1+V" , ID_WINDOW , REFRESH_ID , "F5" ,
8383 ID_DIALOG_AND_WINDOW , EXIT_ID , "CTRL+Q" , ID_DIALOG_AND_WINDOW ,
8484 ABOUT_ID , "CTRL+5 A" , ID_DIALOG_AND_WINDOW , TAG_ID , "ALT+/" ,
85- ID_TEXT , RENAME_ID , "F2" , ID_WINDOW , SHOW_TOOLTIP_ID , "F2" ,
85+ ID_TEXT , RENAME_ID , "F2" , ID_WINDOW , RENAME_ID , "M2+M3+R" , ID_TEXT , SHOW_TOOLTIP_ID , "F2" ,
8686 ID_TEXT , CORR_INDENT_ID , "CTRL+I" , ID_JAVA , INDENT_LINE_ID ,
8787 "CTRL+I" , ID_JS , PASTE_ID , "SHIFT+Insert" , ID_WINDOW , PASTE_ID ,
8888 "CTRL+5 V" , ID_TEXT , };
@@ -317,6 +317,30 @@ public void testManagerLookupShortcut() throws Exception {
317317 assertEquals (paste , match );
318318 }
319319
320+ @ Test
321+ public void testManagerLookupShortcutDeeperContext () throws Exception {
322+ BindingTableManager manager = createManager ();
323+ // Given a BindingTableManager with default active scheme and context manager:
324+ manager .setActiveSchemes (new String [] { "org.eclipse.ui.defaultAcceleratorConfiguration" }, contextManager );
325+ Binding paste = getTestBinding (RENAME_ID , ID_TEXT );
326+ assertNotNull (paste );
327+
328+ ArrayList <Context > window = new ArrayList <>();
329+ Context winContext = contextManager .getContext (ID_WINDOW );
330+ Context dawContext = contextManager .getContext (ID_TEXT );
331+ window .add (winContext );
332+ window .add (dawContext );
333+ ContextSet windowSet = manager .createContextSet (window );
334+ // When getting the best sequence for the paste command:
335+ Binding match = manager .getBestSequenceFor (windowSet , paste .getParameterizedCommand ());
336+ // Then the paste binding with the ID_TEXT context should be returned, because
337+ // it's more specific than the ID_WINDOW context:
338+ assertEquals (paste , match );
339+
340+ // disable context manager in BindingComparator for other tests:
341+ manager .setActiveSchemes (null , null );
342+ }
343+
320344 @ Test
321345 public void testManagerLookupShortcutLongChain () throws Exception {
322346 BindingTableManager manager = createManager ();
@@ -387,6 +411,16 @@ private Binding getTestBinding(String commandId) {
387411 return null ;
388412 }
389413
414+ private Binding getTestBinding (String commandId , String contextId ) {
415+ for (Binding binding : loadedBindings ) {
416+ if (commandId .equals (binding .getParameterizedCommand ().getId ())
417+ && contextId .equals (binding .getContextId ())) {
418+ return binding ;
419+ }
420+ }
421+ return null ;
422+ }
423+
390424 private void assertContextSet (ContextSet set , String [] contextIds ) {
391425 List <Context > contexts = set .getContexts ();
392426 assertEquals (contextIds .length , contexts .size (), contexts .toString ());
0 commit comments