Ejemplo n.º 1
0
  @Override
  public void keyTyped(final KeyEvent e) {
    if (!hist.active()
        || control(e)
        || DELNEXT.is(e)
        || DELPREV.is(e)
        || ESCAPE.is(e)
        || CUT2.is(e)) return;

    final int caret = editor.pos();

    // remember if marked text is to be deleted
    final StringBuilder sb = new StringBuilder(1).append(e.getKeyChar());
    final boolean indent = TAB.is(e) && editor.indent(sb, e.isShiftDown());

    // delete marked text
    final boolean selected = editor.selected() && !indent;
    if (selected) editor.delete();

    final int move = ENTER.is(e) ? editor.enter(sb) : editor.add(sb, selected);

    // refresh history and adjust cursor position
    hist.store(editor.text(), caret, editor.pos());
    if (move != 0) editor.pos(Math.min(editor.size(), caret + move));

    // adjust text height
    scrollCode.invokeLater(true);
    e.consume();
  }
Ejemplo n.º 2
0
 /**
  * Invokes special keys.
  *
  * @param e key event
  * @return {@code true} if special key was processed
  */
 private boolean specialKey(final KeyEvent e) {
   if (PREVTAB.is(e)) {
     gui.editor.tab(false);
   } else if (NEXTTAB.is(e)) {
     gui.editor.tab(true);
   } else if (CLOSETAB.is(e)) {
     gui.editor.close(null);
   } else if (search != null && ESCAPE.is(e)) {
     search.deactivate(true);
   } else {
     return false;
   }
   e.consume();
   return true;
 }