void (@NotNull KeyEvent e) { final KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e); if (keyStroke.equals(myCompletionKeyStroke)) { completionKeyStrokeHappened = true; e.consume(); final String pattern = getTrimmedText(); final int oldPos = myList.getSelectedIndex(); myHistory.add(Pair.create(pattern, oldPos)); final Runnable postRunnable = () -> fillInCommonPrefix(pattern); rebuildList(SelectMostRelevant.INSTANCE, 0, ModalityState.current(), postRunnable); return; } if (keyStroke.equals(backStroke)) { e.consume(); if (!myHistory.isEmpty()) { final String oldText = getTrimmedText(); final int oldPos = myList.getSelectedIndex(); final Pair<String, Integer> last = myHistory.remove(myHistory.size() - 1); myTextField.setText(last.first); myFuture.add(Pair.create(oldText, oldPos)); rebuildList(SelectMostRelevant.INSTANCE, 0, ModalityState.current(), null); } return; } if (keyStroke.equals(forwardStroke)) { e.consume(); if (!myFuture.isEmpty()) { final String oldText = getTrimmedText(); final int oldPos = myList.getSelectedIndex(); final Pair<String, Integer> next = myFuture.remove(myFuture.size() - 1); myTextField.setText(next.first); myHistory.add(Pair.create(oldText, oldPos)); rebuildList(SelectMostRelevant.INSTANCE, 0, ModalityState.current(), null); } return; } int position = myTextField.getCaretPosition(); int code = keyStroke.getKeyCode(); int modifiers = keyStroke.getModifiers(); try { super.processKeyEvent(e); } catch (NullPointerException e1) { if (!Patches.SUN_BUG_ID_6322854) { throw e1; } } finally { if ((code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN) && modifiers == 0) { myTextField.setCaretPosition(position); } } }