diff --git a/openide.text/src/org/openide/text/QuietEditorPane.java b/openide.text/src/org/openide/text/QuietEditorPane.java --- a/openide.text/src/org/openide/text/QuietEditorPane.java +++ b/openide.text/src/org/openide/text/QuietEditorPane.java @@ -60,6 +60,7 @@ import java.awt.dnd.DropTargetEvent; import java.awt.dnd.DropTargetListener; import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.awt.im.InputContext; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -73,6 +74,7 @@ import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JEditorPane; +import javax.swing.KeyStroke; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.TransferHandler; @@ -307,24 +309,48 @@ } } -/* Commented out since virtual height is implemented in the editor (in GapDocumentView) + /* Commented out since virtual height is implemented in the editor (in GapDocumentView) @Override public Dimension getPreferredSize() { - //Avoid always typing at the bottom of the screen by - //adding some virtual height, so the last line of the file - //can always be scrolled up to the middle of the viewport - Dimension result = super.getPreferredSize(); - JViewport port = (JViewport) SwingUtilities.getAncestorOfClass( - JViewport.class, this); - if (port != null) { - int viewHeight = port.getExtentSize().height; - if (result.height > viewHeight) { - result.height += viewHeight / 2; - } + //Avoid always typing at the bottom of the screen by + //adding some virtual height, so the last line of the file + //can always be scrolled up to the middle of the viewport + Dimension result = super.getPreferredSize(); + JViewport port = (JViewport) SwingUtilities.getAncestorOfClass( + JViewport.class, this); + if (port != null) { + int viewHeight = port.getExtentSize().height; + if (result.height > viewHeight) { + result.height += viewHeight / 2; + } + } + return result; + } + */ + + /** + * If true, the immediately following KEY_TYPED event will be discarded. + * Set during KEY_PRESSED processing that results in an action, so the + * potential KEY_TYPED that corresponds to the action key combination + * is not written into the document. + */ + private boolean ignoreNextKeyTyped; + + @Override + protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { + if (e.getID() == KeyEvent.KEY_TYPED && ignoreNextKeyTyped) { + e.consume(); + return false; } - return result; + boolean action = super.processKeyBinding(ks, e, condition, pressed); + if (pressed && e.getID() == KeyEvent.KEY_PRESSED) { + ignoreNextKeyTyped = action; + } else { + ignoreNextKeyTyped = false; + } + return action; } -*/ + /** * Delegating TransferHandler.