src/main/java/com/spinyowl/legui/component/misc/listener/textinput/TextInputKeyEventListener.java
private void keyDeleteAction(TextInput gui, Set<KeyMod> mods) {
    if (gui.isEditable()) {
      TextState textState = gui.getTextState();
      int caretPosition = gui.getCaretPosition();
      int start = gui.getStartSelectionIndex();
      int end = gui.getEndSelectionIndex();
      if (start > end) {
        start = gui.getEndSelectionIndex();
        end = gui.getStartSelectionIndex();
      }
      if (start == end && caretPosition != textState.length()) {
        if (mods.contains(KeyMod.CONTROL)) {
          end = findNextWord(textState.getText(), caretPosition);
          StringBuilder builder = new StringBuilder(textState.getText());
          builder.delete(start, end);
          textState.setText(builder.toString());
          gui.setCaretPosition(start);
          gui.setStartSelectionIndex(start);
          gui.setEndSelectionIndex(start);
        } else {
          StringBuilder builder = new StringBuilder(textState.getText());
          builder.deleteCharAt(caretPosition);
          textState.setText(builder.toString());
          gui.setCaretPosition(caretPosition);
          gui.setStartSelectionIndex(caretPosition);
          gui.setEndSelectionIndex(caretPosition);
        }
      } else {
        StringBuilder builder = new StringBuilder(textState.getText());
        builder.delete(start, end);
        textState.setText(builder.toString());
        gui.setCaretPosition(start);
        gui.setStartSelectionIndex(start);
        gui.setEndSelectionIndex(start);
      }
    }
  }
/**
   * Delete action. Used to delete selected text or symbol after caret or word after caret.
   *
   * @param gui  gui to remove data from text state.
   * @param mods key mods.
   */
Delete action. Used to delete selected text or symbol after caret or word after caret.
@param gui  gui to remove data from text state.
@param mods key mods.
Delete action . Used to delete selected text or symbol after caret or word after caret . @param gui gui to remove data from text state . @param mods key mods .
private void keyDeleteAction(TextInput gui, Set<KeyMod> mods) {
    if (gui.isEditable()) {
      TextState textState = gui.getTextState();
      int caretPosition = gui.getCaretPosition();
      int start = gui.getStartSelectionIndex();
      int end = gui.getEndSelectionIndex();
      if (start > end) {
        start = gui.getEndSelectionIndex();
        end = gui.getStartSelectionIndex();
      }
      if (start == end && caretPosition != textState.length()) {
        if (mods.contains(KeyMod.CONTROL)) {
          end = findNextWord(textState.getText(), caretPosition);
          StringBuilder builder = new StringBuilder(textState.getText());
          builder.delete(start, end);
          textState.setText(builder.toString());
          gui.setCaretPosition(start);
          gui.setStartSelectionIndex(start);
          gui.setEndSelectionIndex(start);
        } else {
          StringBuilder builder = new StringBuilder(textState.getText());
          builder.deleteCharAt(caretPosition);
          textState.setText(builder.toString());
          gui.setCaretPosition(caretPosition);
          gui.setStartSelectionIndex(caretPosition);
          gui.setEndSelectionIndex(caretPosition);
        }
      } else {
        StringBuilder builder = new StringBuilder(textState.getText());
        builder.delete(start, end);
        textState.setText(builder.toString());
        gui.setCaretPosition(start);
        gui.setStartSelectionIndex(start);
        gui.setEndSelectionIndex(start);
      }
    }
  }
private void keyDeleteAction ( TextInput gui , Set < KeyMod > mods ) { if ( gui . isEditable ( ) ) { TextState textState = gui . getTextState ( ) ; int caretPosition = gui . getCaretPosition ( ) ; int start = gui . getStartSelectionIndex ( ) ; int end = gui . getEndSelectionIndex ( ) ; if ( start > end ) { start = gui . getEndSelectionIndex ( ) ; end = gui . getStartSelectionIndex ( ) ; } if ( start == end && caretPosition != textState . length ( ) ) { if ( mods . contains ( KeyMod . CONTROL ) ) { end = findNextWord ( textState . getText ( ) , caretPosition ) ; StringBuilder builder = new StringBuilder ( textState . getText ( ) ) ; builder . delete ( start , end ) ; textState . setText ( builder . toString ( ) ) ; gui . setCaretPosition ( start ) ; gui . setStartSelectionIndex ( start ) ; gui . setEndSelectionIndex ( start ) ; } else { StringBuilder builder = new StringBuilder ( textState . getText ( ) ) ; builder . deleteCharAt ( caretPosition ) ; textState . setText ( builder . toString ( ) ) ; gui . setCaretPosition ( caretPosition ) ; gui . setStartSelectionIndex ( caretPosition ) ; gui . setEndSelectionIndex ( caretPosition ) ; } } else { StringBuilder builder = new StringBuilder ( textState . getText ( ) ) ; builder . delete ( start , end ) ; textState . setText ( builder . toString ( ) ) ; gui . setCaretPosition ( start ) ; gui . setStartSelectionIndex ( start ) ; gui . setEndSelectionIndex ( start ) ; } } }
Delete action.
Delete action .