Ejemplo n.º 1
0
 /** Hides suggestion popup */
 public void hideSuggestion() {
   if (suggestion != null) {
     suggestion.setInvisible();
     // log("Suggestion hidden.");
     suggestion = null; // TODO: check if we dispose the window properly
   }
 }
Ejemplo n.º 2
0
  /** Handles KeyEvents for TextArea (code completion begins from here). */
  public void processKeyEvent(KeyEvent evt) {
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
      if (suggestion != null) {
        if (suggestion.isVisible()) {
          Messages.log("esc key");
          hideSuggestion();
          evt.consume();
          return;
        }
      }

    } else if (evt.getKeyCode() == KeyEvent.VK_ENTER && evt.getID() == KeyEvent.KEY_PRESSED) {
      if (suggestion != null
          && suggestion.isVisible()
          && suggestion.insertSelection(CompletionPanel.KEYBOARD_COMPLETION)) {
        evt.consume();
        // Still try to show suggestions after inserting if it's
        // the case of overloaded methods. See #2755
        if (suggestion.isVisible()) {
          prepareSuggestions(evt);
        }
        return;
      }
    }

    if (evt.getID() == KeyEvent.KEY_PRESSED) {
      switch (evt.getKeyCode()) {
        case KeyEvent.VK_DOWN:
          if (suggestion != null)
            if (suggestion.isVisible()) {
              // log("KeyDown");
              suggestion.moveDown();
              return;
            }
          break;
        case KeyEvent.VK_UP:
          if (suggestion != null)
            if (suggestion.isVisible()) {
              // log("KeyUp");
              suggestion.moveUp();
              return;
            }
          break;
        case KeyEvent.VK_BACK_SPACE:
          Messages.log("BK Key");
          break;
        case KeyEvent.VK_SPACE:
          if (suggestion != null) {
            if (suggestion.isVisible()) {
              Messages.log("Space bar, hide completion list");
              suggestion.setInvisible();
            }
          }
          break;
      }
    }
    super.processKeyEvent(evt);

    // code completion disabled if Java tabs present
    if (!editor.hasJavaTabs()) {
      if (evt.getID() == KeyEvent.KEY_TYPED) {
        processCompletionKeys(evt);
      } else if (!Platform.isMacOS() && evt.getID() == KeyEvent.KEY_RELEASED) {
        processCompletionKeys(evt);
      } else if (Platform.isMacOS() && evt.getID() == KeyEvent.KEY_RELEASED) {
        processControlSpace(evt);
      }
    }
  }