diff -r da1519b4a23d spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EditorContextDispatcher.java --- a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EditorContextDispatcher.java Thu Aug 16 11:39:59 2012 +0200 +++ b/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EditorContextDispatcher.java Fri Aug 17 12:36:34 2012 +0200 @@ -59,6 +59,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.JComponent; import javax.swing.JEditorPane; import javax.swing.JRootPane; import javax.swing.SwingUtilities; @@ -86,6 +87,7 @@ import org.openide.util.RequestProcessor.Task; import org.openide.util.Utilities; import org.openide.util.WeakListeners; +import org.openide.windows.TopComponent; /** * Dispatcher of context-related events and provider of active elements in the IDE. @@ -643,14 +645,8 @@ logger.fine("EditorRegistryListener.propertyChange("+propertyName+": "+evt.getOldValue()+" => "+evt.getNewValue()+")"); } if (propertyName.equals(EditorRegistry.FOCUS_LOST_PROPERTY)) { - Object newFocused = evt.getNewValue(); - if (newFocused instanceof JRootPane) { - JRootPane root = (JRootPane) newFocused; - if (root.isAncestorOf((Component) evt.getOldValue())) { - logger.fine("Focused root."); - root.addFocusListener(this); - return; - } + if (ignoreCurrentComponentUpdate((Component) evt.getNewValue())) { + return ; } } if (propertyName.equals(EditorRegistry.FOCUS_GAINED_PROPERTY) || @@ -725,7 +721,45 @@ return ; } } - update(true); + if (!ignoreCurrentComponentUpdate(e.getOppositeComponent())) { + update(true); + } + } + + /** + * Test if the last focused component stays as the current one, or not. + * @param newFocused The newly focused component + * @return if the current component should be updated, or not. + */ + private boolean ignoreCurrentComponentUpdate(Component newFocused) { + if (EditorRegistry.focusedComponent() == null) { + JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent(); + if (logger.isLoggable(Level.FINE)) { + logger.fine("lastFocusedComponent = "+lastFocusedComponent); + logger.fine("newFocused = "+newFocused); + } + if (lastFocusedComponent != null && newFocused != null) { + // if the last focused component is in the same TopComponent as the newly focused, + // keep the currentTextComponent as the current one. + TopComponent activated = TopComponent.getRegistry().getActivated(); + if (logger.isLoggable(Level.FINE)) { + logger.fine("activated = "+activated); + } + if (activated != null) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("isAncestorOf = "+(activated.isAncestorOf(lastFocusedComponent) && (newFocused instanceof JRootPane || activated.isAncestorOf(newFocused)))); + } + if (activated.isAncestorOf(lastFocusedComponent) && + (activated.isAncestorOf(newFocused) || // either both are in the activated TC, + newFocused instanceof JRootPane && // or JRootPane is the newly focused (menu popup) + ((JRootPane) newFocused).isAncestorOf(lastFocusedComponent))) { + newFocused.addFocusListener(this); + return true; + } + } + } + } + return false; } }