Exemplo 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();
  }
Exemplo n.º 2
0
 @Override
 public final void componentResized(final ComponentEvent e) {
   resizeCode.invokeLater();
 }
Exemplo n.º 3
0
 /**
  * Finishes a command.
  *
  * @param old old cursor position; store entry to history if position != -1
  */
 private void finish(final int old) {
   if (old != -1) hist.store(editor.text(), old, editor.pos());
   scrollCode.invokeLater(true);
   release(Action.CHECK);
 }
Exemplo n.º 4
0
 /**
  * Auto-completes a string at the specified position.
  *
  * @param string string
  * @param start start position
  */
 private void complete(final String string, final int start) {
   final int caret = editor.pos();
   editor.complete(string, start);
   hist.store(editor.text(), caret, editor.pos());
   scrollCode.invokeLater(true);
 }