src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java
public void write(String text) {
        if (text.isEmpty())
            return;

        if (this.lines.isEmpty()) {
            this.lines.add(text);
            this.cursor.toEnd();
            return;
        }
        this.selection.erase();

        int oldSize = this.lines.size();

        var whole = this.getText();
        int position = this.cursor.getPosition();

        String newText;
        if (position >= whole.length()) {
            newText = whole + text;
        } else {
            newText = whole.substring(0, position) + text + whole.substring(position);
        }

        this.lines.clear();
        this.lines.setLines(Arrays.asList(newText.split("\n")));

        for (int i = 0; i < text.length(); i++) {
            if (text.charAt(i) == '\n')
                this.cursor.moveRight();
            this.cursor.moveRight();
        }
        if (oldSize < this.lines.size()) this.cursor.moveRight();
    }
/**
     * Writes text where the cursor is.
     *
     * @param text the text to write
     */
Writes text where the cursor is.
@param text the text to write
Writes text where the cursor is . @param text the text to write
public void write(String text) {
        if (text.isEmpty())
            return;
        if (this.lines.isEmpty()) {
            this.lines.add(text);
            this.cursor.toEnd();
            return;
        }
        this.selection.erase();
        int oldSize = this.lines.size();
        var whole = this.getText();
        int position = this.cursor.getPosition();
        String newText;
        if (position >= whole.length()) {
            newText = whole + text;
        } else {
            newText = whole.substring(0, position) + text + whole.substring(position);
        }
        this.lines.clear();
        this.lines.setLines(Arrays.asList(newText.split("\n")));
        for (int i = 0; i < text.length(); i++) {
            if (text.charAt(i) == '\n')
                this.cursor.moveRight();
            this.cursor.moveRight();
        }
        if (oldSize < this.lines.size()) this.cursor.moveRight();
    }
public void write ( String text ) { if ( text . isEmpty ( ) ) return ; if ( this . lines . isEmpty ( ) ) { this . lines . add ( text ) ; this . cursor . toEnd ( ) ; return ; } this . selection . erase ( ) ; int oldSize = this . lines . size ( ) ; var whole = this . getText ( ) ; int position = this . cursor . getPosition ( ) ; String newText ; if ( position >= whole . length ( ) ) { newText = whole + text ; } else { newText = whole . substring ( 0 , position ) + text + whole . substring ( position ) ; } this . lines . clear ( ) ; this . lines . setLines ( Arrays . asList ( newText . split ( "\n" ) ) ) ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { if ( text . charAt ( i ) == '\n' ) this . cursor . moveRight ( ) ; this . cursor . moveRight ( ) ; } if ( oldSize < this . lines . size ( ) ) this . cursor . moveRight ( ) ; }
Writes text where the cursor is.
Writes text where the cursor is .