<commit_before>// Copyright (c) 2006-2009 by <NAME> <<EMAIL>>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the License.txt file included with this file.


/** @scope modules */

// command names taken from:
// http://developer.mozilla.org/en/docs/Editor_Embedding_Guide

/** @instance editor */
const Editor = Module("editor", {
    requires: ["config", "abbreviations"],

    init: function () {
        // store our last search with f, F, t or T
        this._lastFindChar = null;
        this._lastFindCharFunc = null;
        this._visualMode = "";
    },

    line: function () {
        let line = 1;
        let text = Editor.getEditor().value;
        for (let i = 0; i < Editor.getEditor().selectionStart; i++)
            if (text[i] == "\n")
                line++;
        return line;
    },

    col: function () {
        let col = 1;
        let text = Editor.getEditor().value;
        for (let i = 0; i < Editor.getEditor().selectionStart; i++) {
            col++;
            if (text[i] == "\n")
                col = 1;
        }
        return col;
    },

    unselectText: function () {
        let e = Editor.getEditor();
        if (e instanceof Window) {
            e.getSelection().collapseToStart();
        } else {
            // A error occurs if the element has been removed when "e.selectionStart" is executed.
            try {
                if (e && e.selectionEnd)
                    e.selectionEnd = e.selectionStart;
            }
            catch (e) {}
        }
    },

    selectedText: function () {
        let e = Editor.getEditor();
        if (e instanceof Window)
            return e.getSelection().toString();
        let text = e.value;
        return text.substring(e.selectionStart, e.selectionEnd);
    },


    pasteClipboard: function () {

            if (!liberator.has("Unix")) {
                this.executeCommand("cmd_paste");
                return;
            }
    
            let elem = liberator.focus;
    
            if (elem.setSelectionRange && util.readFromClipboard()) {
                // readFromClipboard would return 'undefined' if not checked
                // dunno about .setSelectionRange
                // This is a hacky fix - but it works.
                let curTop = elem.scrollTop;
                let curLeft = elem.scrollLeft;
    
                let rangeStart = elem.selectionStart; // caret position
                let rangeEnd = elem.selectionEnd;
                let tempStr1 = elem.value.substring(0, rangeStart);
                let tempStr2 = util.readFromClipboard();
                let tempStr3 = elem.value.substring(rangeEnd);
                elem.value = tempStr1 + tempStr2 + tempStr3;
                elem.selectionStart = rangeStart + tempStr2.length;
                elem.selectionEnd = elem.selectionStart;
    
                elem.scrollTop = curTop;
                elem.scrollLeft = curLeft;
            }
    },

    // count is optional, defaults to 1
    executeCommand: function (cmd, count) {
        let controller = Editor.getController(cmd);
        if (!controller || !controller.supportsCommand(cmd) || !controller.isCommandEnabled(cmd)) {
            liberator.beep();
            return false;
        }
<commit_msg>fix command line Shift+Insert paste on Linux<commit_after>// Copyright (c) 2006-2009 by <NAME> <<EMAIL>>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the License.txt file included with this file.


/** @scope modules */

// command names taken from:
// http://developer.mozilla.org/en/docs/Editor_Embedding_Guide

/** @instance editor */
const Editor = Module("editor", {
    requires: ["config", "abbreviations"],

    init: function () {
        // store our last search with f, F, t or T
        this._lastFindChar = null;
        this._lastFindCharFunc = null;
        this._visualMode = "";
    },

    line: function () {
        let line = 1;
        let text = Editor.getEditor().value;
        for (let i = 0; i < Editor.getEditor().selectionStart; i++)
            if (text[i] == "\n")
                line++;
        return line;
    },

    col: function () {
        let col = 1;
        let text = Editor.getEditor().value;
        for (let i = 0; i < Editor.getEditor().selectionStart; i++) {
            col++;
            if (text[i] == "\n")
                col = 1;
        }
        return col;
    },

    unselectText: function () {
        let e = Editor.getEditor();
        if (e instanceof Window) {
            e.getSelection().collapseToStart();
        } else {
            // A error occurs if the element has been removed when "e.selectionStart" is executed.
            try {
                if (e && e.selectionEnd)
                    e.selectionEnd = e.selectionStart;
            }
            catch (e) {}
        }
    },

    selectedText: function () {
        let e = Editor.getEditor();
        if (e instanceof Window)
            return e.getSelection().toString();
        let text = e.value;
        return text.substring(e.selectionStart, e.selectionEnd);
    },


    pasteClipboard: function () {

            if (!liberator.has("Unix")) {
                this.executeCommand("cmd_paste");
                return;
            }
    
            // clear completion preview so it does not get turned into regular text
            if (commandline._completions)
                commandline._completions.previewClear();

            let elem = liberator.focus;
    
            if (elem.setSelectionRange && util.readFromClipboard()) {
                // readFromClipboard would return 'undefined' if not checked
                // dunno about .setSelectionRange
                // This is a hacky fix - but it works.
                let curTop = elem.scrollTop;
                let curLeft = elem.scrollLeft;
    
                let rangeStart = elem.selectionStart; // caret position
                let rangeEnd = elem.selectionEnd;
                let tempStr1 = elem.value.substring(0, rangeStart);
                let tempStr2 = util.readFromClipboard();
                let tempStr3 = elem.value.substring(rangeEnd);
                elem.value = tempStr1 + tempStr2 + tempStr3;
                elem.selectionStart = rangeStart + tempStr2.length;
                elem.selectionEnd = elem.selectionStart;
    
                elem.scrollTop = curTop;
                elem.scrollLeft = curLeft;
            }

            // update completion preview as would happen with Ctrl+v or mouse paste
            if (commandline._completions && options.autocomplete)
                commandline._completions.complete(true, false);
    },

    // count is optional, defaults to 1
    executeCommand: function (cmd, count) {
        let controller = Editor.getController(cmd);
        if (!controller || !controller.supportsCommand(cmd) || !controller.isCommandEnabled(cmd)) {
            liberator.beep();
            return false;
        }

{'fraction_non_alphanumeric': 0.11060433295324971, 'fraction_numerical': 0.006271379703534778, 'mean_word_length': 1.6700913242009132, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '2938634', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1805, 'n_words': 517}