<commit_before>var session = require("zed/session");

function Stripper(info, callback) {
    this.path = info.path;
    this.min = info.inserts.preferences.trimEmptyLines ? -1 : 0;
    this.lines = info.inserts.lines;
    this.currentLine = info.inserts.cursor.row;
    this.final = callback;

    // Don't strip mid-snippet.
    if (info.inserts.isInsertingSnippet) {
        callback();
    } else {
        this.stripTrailing();
    }
}

Stripper.prototype = {
    stripTrailing: function() {
        // Strip spaces from the ends of lines.
        for (var i = 0; i < this.lines.length; i++) {
            // Preserve spaces on the line we're on.
            if (i == this.currentLine) {
                continue;
            }

            // Don't do the strip if the line contains only spaces
            // and the preference to trimEmptyLines isn't set.
            var column = this.lines[i].search(/\s+$/);
            if (column > this.min) {
                session.removeInLine(this.path, i, column, this.lines[i].length);
            }
        }

        this.checkEOF();
    },

    checkEOF: function() {
        var lastTwo = this.lines.slice(-2);
        if (lastTwo[1] !== "") {
            // Enforce newline at end of file.
            session.append(this.path, "\n", this.final);
        } else if (lastTwo[0] === "" && lastTwo[1] === "") {
            // Strip blank lines from the end.
            this.stripEndLines();
        } else {
            // Perfect!!
            this.final();
        }
    },

    stripEndLines: function() {
        var len = this.lines.length;
        // Don't strip beyond the cursor position.<commit_msg>Call the final callback in all cases.<commit_after>var session = require("zed/session");

function Stripper(info, callback) {
    this.path = info.path;
    this.min = info.inserts.preferences.trimEmptyLines ? -1 : 0;
    this.lines = info.inserts.lines;
    this.currentLine = info.inserts.cursor.row;
    this.final = callback;

    // Don't strip mid-snippet.
    if (info.inserts.isInsertingSnippet) {
        callback();
    } else {
        this.stripTrailing();
    }
}

Stripper.prototype = {
    stripTrailing: function() {
        // Strip spaces from the ends of lines.
        for (var i = 0; i < this.lines.length; i++) {
            // Preserve spaces on the line we're on.
            if (i == this.currentLine) {
                continue;
            }

            // Don't do the strip if the line contains only spaces
            // and the preference to trimEmptyLines isn't set.
            var column = this.lines[i].search(/\s+$/);
            if (column > this.min) {
                session.removeInLine(this.path, i, column, this.lines[i].length);
            }
        }

        this.checkEOF();
    },

    checkEOF: function() {
        var lastTwo = this.lines.slice(-2);
        if (lastTwo[1] !== "") {
            // Enforce newline at end of file.
            session.append(this.path, "\n", this.final);
        } else if (lastTwo[0] === "" && lastTwo[1] === "") {
            // Strip blank lines from the end.
            this.stripEndLines();
        }
        this.final();
    },

    stripEndLines: function() {
        var len = this.lines.length;
        // Don't strip beyond the cursor position.
{'fraction_non_alphanumeric': 0.1358958837772397, 'fraction_numerical': 0.00423728813559322, 'mean_word_length': 1.7336641852770884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4876725', 'n_tokens_mistral': 992, 'n_tokens_neox': 957, 'n_words': 249}