src/main/java/com/spinyowl/legui/component/misc/listener/textarea/TextAreaFieldKeyEventListener.java
private void keyEnterAction(TextAreaField gui) {
    if (gui.isEditable()) {
      int start = gui.getStartSelectionIndex();
      int end = gui.getEndSelectionIndex();
      TextState textState = gui.getTextState();
      StringBuilder builder = new StringBuilder(textState.getText());
      int caretPosition = gui.getCaretPosition();

      if (start != end) {
        if (start > end) {
          start = gui.getEndSelectionIndex();
          end = gui.getStartSelectionIndex();
        }

        builder.delete(start, end);
        textState.setText(builder.toString());
        caretPosition = start;
      }

      builder.insert(caretPosition, "\n");
      textState.setText(builder.toString());

      int newCaretPosition = caretPosition + 1;

      gui.setStartSelectionIndex(newCaretPosition);
      gui.setEndSelectionIndex(newCaretPosition);
      gui.setCaretPosition(newCaretPosition);
    }
  }
/**
   * Action on Enter key. Adds new line symbol on caret position.
   *
   * @param gui gui to add new line.
   */
Action on Enter key. Adds new line symbol on caret position.
@param gui gui to add new line.
Action on Enter key . Adds new line symbol on caret position . @param gui gui to add new line .
private void keyEnterAction(TextAreaField gui) {
    if (gui.isEditable()) {
      int start = gui.getStartSelectionIndex();
      int end = gui.getEndSelectionIndex();
      TextState textState = gui.getTextState();
      StringBuilder builder = new StringBuilder(textState.getText());
      int caretPosition = gui.getCaretPosition();
      if (start != end) {
        if (start > end) {
          start = gui.getEndSelectionIndex();
          end = gui.getStartSelectionIndex();
        }
        builder.delete(start, end);
        textState.setText(builder.toString());
        caretPosition = start;
      }
      builder.insert(caretPosition, "\n");
      textState.setText(builder.toString());
      int newCaretPosition = caretPosition + 1;
      gui.setStartSelectionIndex(newCaretPosition);
      gui.setEndSelectionIndex(newCaretPosition);
      gui.setCaretPosition(newCaretPosition);
    }
  }
private void keyEnterAction ( TextAreaField gui ) { if ( gui . isEditable ( ) ) { int start = gui . getStartSelectionIndex ( ) ; int end = gui . getEndSelectionIndex ( ) ; TextState textState = gui . getTextState ( ) ; StringBuilder builder = new StringBuilder ( textState . getText ( ) ) ; int caretPosition = gui . getCaretPosition ( ) ; if ( start != end ) { if ( start > end ) { start = gui . getEndSelectionIndex ( ) ; end = gui . getStartSelectionIndex ( ) ; } builder . delete ( start , end ) ; textState . setText ( builder . toString ( ) ) ; caretPosition = start ; } builder . insert ( caretPosition , "\n" ) ; textState . setText ( builder . toString ( ) ) ; int newCaretPosition = caretPosition + 1 ; gui . setStartSelectionIndex ( newCaretPosition ) ; gui . setEndSelectionIndex ( newCaretPosition ) ; gui . setCaretPosition ( newCaretPosition ) ; } }
Action on Enter key.
Action on Enter key .