Пример #1
0
  public void deletBackwards() {
    if (caretPos == 0) {
      TextBlock tb = caretBlock.previousTextBlock();
      if (tb == null) {
        return;

      } else {
        caretBlock = tb;
        caretPos = caretBlock.textLength();
      }
    }

    if (caretBlock.textLength() == 1) {
      TextBlock tb = caretBlock.previousTextBlock();
      int newPos = tb.textLength();
      caretBlock.remove();
      if (tb == null) {
        caretBlock = textBoard.firstTextBlock();
        caretPos = 0;
      } else {
        caretBlock = tb;
        caretPos = newPos;
      }

    } else {
      caretBlock.deleteCharBefore(caretPos);
      caretPos -= 1;
    }

    textBoard.repaint();
  }
Пример #2
0
  private void insertPuncBeforeNonPunc(TextBlock tb, char c) {
    TextBlock bpr = tb.previousTextBlock();
    if (bpr instanceof PunctuationBlock) {
      insertPuncInPunc(bpr, c, bpr.textLength());

    } else {
      addNewPuncBlockAfter(bpr, c);
    }
  }
Пример #3
0
  private void insertLetterBeforeNonWord(TextBlock tb, char c) {
    TextBlock bpr = tb.previousTextBlock();
    if (bpr instanceof WordBlock) {
      insertLetterInWord(bpr, c, bpr.textLength());

    } else {
      addNewWordBlockAfter(bpr, c);
    }
  }
Пример #4
0
  public void caretLeft() {
    if (caretBlock == null) {
      return;
    }
    if (caretPos > 0) {
      caretPos -= 1;
    } else {
      TextBlock tb = caretBlock.previousTextBlock();
      if (tb == null) {

      } else {
        caretBlock = tb;
        caretPos = caretBlock.textLength() - 1;
      }
    }

    textBoard.repaint();
  }
Пример #5
0
  private void newline() {
    if (caretPos == 0) {
      TextBlock tbp = caretBlock.previousTextBlock();
      if (tbp != null) {
        tbp.newlineAfter();
      }

    } else if (caretPos == caretBlock.textLength()) {
      caretBlock.newlineAfter();
      caretBlock = caretBlock.nextTextBlock();
      caretPos = 1;

    } else {
      caretBlock.insertNewline(caretPos);
      caretBlock = caretBlock.nextTextBlock();
      caretPos = 1;
    }
  }