<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package htmleditor;

/**
 *
 * @author <NAME> (<EMAIL>)
 */
/*
 * The Command to close the editor.
 */

import java.util.ArrayList;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.scene.control.Tab;

/**
 *
 * @author aac6012
 */
public class IndentCommand implements Command{
    HTMLEditor editor ;
    IndentType type;
    
    
    public IndentCommand(HTMLEditor editor, IndentType t){
        this.editor = editor;
        this.type = t;
    }

    
    public void execute(Event t) {
        String indent = new String(new char[editor.indent_size]).replace("\0", " ");
        if(type == IndentType.INDENT_ALL){
            
            System.out.println("Indenting entire buffer...");
            
            String[] lines = editor.getBuffer().split("\n");
            String buffer_out = "";
            for (int i = 0; i < lines.length; i++) {
                buffer_out += indent + lines[i] + "\n"; 
            }
            editor.setBuffer(buffer_out);
        }else if( type == IndentType.INDENT_CURRENT_LINE){
            
            System.out.println("Indenting current line...");
            
            editor.insertIntoBufferAtPos(indent, editor.getCurrentLineStartPosition() + 1);
            
            
            
        }else if( type == IndentType.INDENT_SELECTION){     
            
            System.out.println("Indenting selection...");
            
        }
    }
}

enum IndentType{
    INDENT_CURRENT_LINE, INDENT_SELECTION, INDENT_ALL;<commit_msg>Implementing auto-indent.  - Indent selection completed :boom:<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package htmleditor;

/**
 *
 * @author <NAME> (<EMAIL>)
 */
/*
 * The Command to close the editor.
 */

import java.util.ArrayList;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;

/**
 *
 * @author aac6012
 */
public class IndentCommand implements Command{
    HTMLEditor editor ;
    IndentType type;
    
    
    public IndentCommand(HTMLEditor editor, IndentType t){
        this.editor = editor;
        this.type = t;
    }

    
    public void execute(Event t) {
        String indent = new String(new char[editor.indent_size]).replace("\0", " ");
        if(type == IndentType.INDENT_ALL){
            
            System.out.println("Indenting entire buffer...");
            
            String[] lines = editor.getBuffer().split("\n");
            String buffer_out = "";
            for (int i = 0; i < lines.length; i++) {
                buffer_out += indent + lines[i] + "\n"; 
            }
            editor.setBuffer(buffer_out);
        }else if( type == IndentType.INDENT_CURRENT_LINE){
            
            System.out.println("Indenting current line...");
            
            editor.insertIntoBufferAtPos(indent, editor.getCurrentLineStartPosition() + 1);
            
            
            
        }else if( type == IndentType.INDENT_SELECTION){     
            
            System.out.println("Indenting selection...");
            
            TextArea ta = editor.getTextArea();
            
            String lside = ta.getText(0, ta.getSelection().getStart());
            String selection = ta.getText(ta.getSelection().getStart(), ta.getSelection().getEnd());
            String rside = ta.getText(ta.getSelection().getEnd(), ta.getText().length());
            
            String[] lines = selection.split("\n");
            String buffer_out = "";
            for (int i = 0; i < lines.length; i++) {
                buffer_out += indent + lines[i];
                if( i < lines.length - 1){
                    buffer_out += "\n"; 
                }
                
            }
            
            editor.setBuffer(lside + buffer_out + rside);
            
        }
    }
}

enum IndentType{
    INDENT_CURRENT_LINE, INDENT_SELECTION, INDENT_ALL;
{'fraction_non_alphanumeric': 0.11844252739566333, 'fraction_numerical': 0.003963627885287946, 'mean_word_length': 1.8888888888888888, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4142643', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1189, 'n_words': 281}