Java Code Examples for com.intellij.util.ui.UIUtil#isReallyTypedEvent()

The following examples show how to use com.intellij.util.ui.UIUtil#isReallyTypedEvent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpeedSearchBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void processKeyEvent(KeyEvent e) {
  if (e.isAltDown()) return;
  if (e.isShiftDown() && isNavigationKey(e.getKeyCode())) return;
  if (mySearchPopup != null) {
    mySearchPopup.processKeyEvent(e);
    return;
  }
  if (!isSpeedSearchEnabled()) return;
  if (e.getID() == KeyEvent.KEY_TYPED) {
    if (!UIUtil.isReallyTypedEvent(e)) return;

    char c = e.getKeyChar();
    if (Character.isLetterOrDigit(c) || !Character.isWhitespace(c) && SpeedSearch.PUNCTUATION_MARKS.indexOf(c) != -1) {
      manageSearchPopup(new SearchPopup(String.valueOf(c)));
      e.consume();
    }
  }
}
 
Example 2
Source File: SpeedSearch.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void processKeyEvent(KeyEvent e) {
  if (e.isConsumed() || !myEnabled) return;

  String old = myString;
  if (e.getID() == KeyEvent.KEY_PRESSED) {
    if (KeymapUtil.isEventForAction(e, "EditorDeleteToWordStart")) {
      if (isHoldingFilter()) {
        while (!myString.isEmpty() && !Character.isWhitespace(myString.charAt(myString.length() - 1))) {
          backspace();
        }
        e.consume();
      }
    }
    else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
      backspace();
      e.consume();
    }
    else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      if (isHoldingFilter()) {
        updatePattern("");
        e.consume();
      }
    }
  }
  else if (e.getID() == KeyEvent.KEY_TYPED) {
    if (!UIUtil.isReallyTypedEvent(e)) return;
    // key-char is good only on KEY_TYPED
    // for example: key-char on ctrl-J PRESSED is \n
    // see https://en.wikipedia.org/wiki/Control_character
    char ch = e.getKeyChar();
    if (Character.isLetterOrDigit(ch) || !startedWithWhitespace(ch) && PUNCTUATION_MARKS.indexOf(ch) != -1) {
      type(Character.toString(ch));
      e.consume();
    }
  }

  if (!old.equalsIgnoreCase(myString)) {
    update();
  }
}
 
Example 3
Source File: ActionMacroManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void postProcessKeyEvent(KeyEvent e) {
  if (e.getID() != KeyEvent.KEY_PRESSED) return;
  if (myLastActionInputEvent.contains(e)) {
    myLastActionInputEvent.remove(e);
    return;
  }
  final boolean modifierKeyIsPressed = e.getKeyCode() == KeyEvent.VK_CONTROL || e.getKeyCode() == KeyEvent.VK_ALT || e.getKeyCode() == KeyEvent.VK_META || e.getKeyCode() == KeyEvent.VK_SHIFT;
  if (modifierKeyIsPressed) return;

  final boolean ready = IdeEventQueue.getInstance().getKeyEventDispatcher().isReady();
  final boolean isChar = e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && UIUtil.isReallyTypedEvent(e);
  final boolean hasActionModifiers = e.isAltDown() | e.isControlDown() | e.isMetaDown();
  final boolean plainType = isChar && !hasActionModifiers;
  final boolean isEnter = e.getKeyCode() == KeyEvent.VK_ENTER;

  if (plainType && ready && !isEnter) {
    myRecordingMacro.appendKeytyped(e.getKeyChar(), e.getKeyCode(), e.getModifiers());
    notifyUser(Character.valueOf(e.getKeyChar()).toString(), true);
  }
  else if ((!plainType && ready) || isEnter) {
    final String stroke = KeyStroke.getKeyStrokeForEvent(e).toString();

    final int pressed = stroke.indexOf("pressed");
    String key = stroke.substring(pressed + "pressed".length());
    String modifiers = stroke.substring(0, pressed);

    String shortcut = (modifiers.replaceAll("ctrl", "control").trim() + " " + key.trim()).trim();

    myRecordingMacro.appendShortcut(shortcut);
    notifyUser(KeymapUtil.getKeystrokeText(KeyStroke.getKeyStrokeForEvent(e)), false);
  }
}