<commit_before>if (typeof GQ == "undefined") var GQ = function(){};

// autocomplete dialog stuff
GQ.au = {};

GQ.au.active = false;

// get position of carret
GQ.au.getCaret = function(params, el) {
  if (params.selection){
    return params.selection.baseOffset;
  }

  if (el.selectionStart) {
    return el.selectionStart;
  } else if (document.selection) {
    el.focus();

    var r = document.selection.createRange();
    if (r == null) {
      return 0;
    }

    var re = el.createTextRange(),
        rc = re.duplicate();
    re.moveToBookmark(r.getBookmark());
    rc.setEndPoint('EndToStart', re);

    return rc.text.length;
  }

  return 0;
}

// create mirror element (mirrors the Textarea).
// we need to do this in order to display the autocomplete dialog
GQ.au.createMirror = function(params, source) {
    var mirrorStyles = [
        // Box Styles.
        'box-sizing', 'height', 'width', 'padding-bottom'
        , 'padding-left', 'padding-right', 'padding-top'

        // Font stuff.
        , 'font-family', 'font-size', 'font-style' 
        , 'font-variant', 'font-weight'

        // Spacing etc.
        , 'word-spacing', 'letter-spacing', 'line-height'
        , 'text-decoration', 'text-indent', 'text-transform' 

        // The direction.
        , 'direction'
        ];

    var mirror = document.createElement("div");
    mirror.setAttribute("id", "qt-mirror");
    source.parentElement.appendChild(mirror);

    // copy all styles
    for (var i = 0, style; style = mirrorStyles[i]; i++) {
        mirror.style.setProperty(style, source.style.getPropertyValue(style));
    }

    // and classes
    for (var i = 0, cl; cl = source.classList[i]; i++){
        mirror.classList.add(cl);
    }

    var sourcePos = $(source).position();
    mirror.style.top = sourcePos.top + "px";
    mirror.style.left = sourcePos.left + "px";

    var caretPos = GQ.au.getCaret(params, source);
    var str = params.value;
    var pre = document.createTextNode(str.substring(0, caretPos));
    var post = document.createTextNode(str.substring(caretPos));
    var caret = document.createElement("span");

    caret.setAttribute('id', 'qt-caret');
    caret.innerHTML = "&nbsp;";

    mirror.appendChild(pre);
    mirror.appendChild(caret);
    mirror.appendChild(post);

    mirror.scrollTop = source.scrollTop + 10; 
}

// Show a list of quicktext the user can choose from.
GQ.au.show = function(params, quicktexts, source){
    $("#qt-au-list", params.iFrameDoc).remove();
    $("#qt-mirror", params.iFrameDoc).remove();

    if (params['word'].length >= 3 && quicktexts.length) {
        GQ.au.active = true;

        var listEl = $("<ul id='qt-au-list'>")
        var list = "<% _.each(quicktexts, function(qt) { %>\
            <li class='qt-au-item' id='qt-item-<%= qt.id %>'><%= qt.shortcut %> - <%= qt.title %></li>\
        <% }); %>\
        </ul>";
        var content = _.template(list, {quicktexts: quicktexts});
        listEl.html(content);

        mirror = GQ.au.createMirror(params, source);
        var sourcePos = $(source).position();
        var caretPos = $("#qt-caret", params.iFrameDoc).position();

        listEl.css('top', sourcePos.top + caretPos.top + "px");
        listEl.css('left', sourcePos.left + caretPos.left + "px");
        $(source).after(listEl);

        // make the first element active
        $('.qt-au-item:first', params.iFrameDoc).addClass("qt-au-item-active");

        // attach hover events
        $('.qt-au-item', params.iFrameDoc).hover(function(){
            $(".qt-au-item", params.iFrameDoc).removeClass("qt-au-item-active");
            $(this).addClass("qt-au-item-active");
        });
    }
};

GQ.au.remove = function(doc) {
    var iframe = document.querySelector('iframe.editable');
    if (iframe){
        doc = iframe.contentDocument;
    }
    $("#qt-au-list", doc).remove();
};

GQ.au.move = function(dir) {
    var activeEl = $(".qt-au-item-active");
    activeEl.removeClass("qt-au-item-active");
    if (dir == "up") {
        activeEl.prev().addClass("qt-au-item-active");
    } else if (dir == "down") {
        activeEl.next().addClass("qt-au-item-active");
    }
};

// Given a quicktext object try to insert it
GQ.au.handleInsertion = function(source, parseWord) {
    if (GQ.isContentEditable) {
        if (GQ.attachedIframe){ // we are in an iframe
            GQ.handleIframe(source, parseWord,
                function(params, result){
                    params['base'].data = result;
                    return result;
                },
                function(params, newCursorPos){
                    var range = params['iFrameDoc'].createRange();
                    range.setStart(params['base'], newCursorPos);
                    range.setEnd(params['base'], newCursorPos);
                    params['selection'].removeAllRanges();
                    params['selection'].addRange(range);
                }
            );
        } else { // in the 'new style' editor
            GQ.handleNewStyle(source, parseWord,
                function(params, result){
                    params['base'].data = result;
                    return result;<commit_msg>Fixed the completion dialog<commit_after>if (typeof GQ == "undefined") var GQ = function(){};

// autocomplete dialog stuff
GQ.au = {};

GQ.au.active = false;

// get position of carret
GQ.au.getCaret = function(params, el) {
  if (params.selection){
    return params.selection.baseOffset;
  }

  if (el.selectionStart) {
    return el.selectionStart;
  } else if (document.selection) {
    el.focus();

    var r = document.selection.createRange();
    if (r == null) {
      return 0;
    }

    var re = el.createTextRange(),
        rc = re.duplicate();
    re.moveToBookmark(r.getBookmark());
    rc.setEndPoint('EndToStart', re);

    return rc.text.length;
  }

  return 0;
}

// create mirror element (mirrors the Textarea).
// we need to do this in order to display the autocomplete dialog
GQ.au.createMirror = function(params, source) {
    var mirrorStyles = [
        // Box Styles.
        'box-sizing', 'height', 'width', 'padding-bottom'
        , 'padding-left', 'padding-right', 'padding-top'

        // Font stuff.
        , 'font-family', 'font-size', 'font-style' 
        , 'font-variant', 'font-weight'

        // Spacing etc.
        , 'word-spacing', 'letter-spacing', 'line-height'
        , 'text-decoration', 'text-indent', 'text-transform' 

        // The direction.
        , 'direction'
        ];

    var mirror = document.createElement("div");
    mirror.setAttribute("id", "qt-mirror");
    source.parentElement.appendChild(mirror);

    // copy all styles
    for (var i = 0, style; style = mirrorStyles[i]; i++) {
        mirror.style.setProperty(style, source.style.getPropertyValue(style));
    }

    // and classes
    for (var i = 0, cl; cl = source.classList[i]; i++){
        mirror.classList.add(cl);
    }

    var sourcePos = $(source).position();
    mirror.style.top = sourcePos.top + "px";
    mirror.style.left = sourcePos.left + "px";

    var caretPos = GQ.au.getCaret(params, source);
    var str = params.value;
    var pre = document.createTextNode(str.substring(0, caretPos));
    var post = document.createTextNode(str.substring(caretPos));
    var caret = document.createElement("span");

    caret.setAttribute('id', 'qt-caret');
    caret.innerHTML = "&nbsp;";

    mirror.appendChild(pre);
    mirror.appendChild(caret);
    mirror.appendChild(post);

    mirror.scrollTop = source.scrollTop + 10; 
}

// Show a list of quicktext the user can choose from.
GQ.au.show = function(params, quicktexts, source){
    $("#qt-au-list", params.iFrameDoc).remove();
    $("#qt-mirror", params.iFrameDoc).remove();

    if (params['word'].length >= 3 && quicktexts.length) {
        GQ.au.active = true;

        var listEl = $("<ul id='qt-au-list'>")
        var list = "<% _.each(quicktexts, function(qt) { %>\
            <li class='qt-au-item' id='qt-item-<%= qt.id %>'><%= qt.shortcut %> - <%= qt.title %></li>\
        <% }); %>\
        </ul>";
        var content = _.template(list, {quicktexts: quicktexts});
        listEl.html(content);

        mirror = GQ.au.createMirror(params, source);
        var sourcePos = $(source).position();
        var caretPos = $("#qt-caret", params.iFrameDoc).position();

        listEl.css('top', sourcePos.top + caretPos.top + "px");
        listEl.css('left', sourcePos.left + caretPos.left + "px");
        $(source).after(listEl);

        // make the first element active
        $('.qt-au-item:first', params.iFrameDoc).addClass("qt-au-item-active");

        // attach hover events
        $('.qt-au-item', params.iFrameDoc).hover(function(){
            $(".qt-au-item", params.iFrameDoc).removeClass("qt-au-item-active");
            $(this).addClass("qt-au-item-active");
        });
    }
};

GQ.au.remove = function(doc) {
    var iframe = document.querySelector('iframe.editable');
    if (iframe){
        doc = iframe.contentDocument;
    }
    $("#qt-au-list", doc).remove();
    GQ.au.active = false;
};

GQ.au.move = function(dir) {
    var activeEl = $(".qt-au-item-active");
    var nextEl = null;
    if (dir == "up") {
        nextEl = activeEl.prev('.qt-au-item');
    } else if (dir == "down") {
        nextEl = activeEl.next('.qt-au-item');
    }

    if (nextEl.length){
        activeEl.removeClass('qt-au-item-active');
        nextEl.addClass('qt-au-item-active');
    }
};

// Given a quicktext object try to insert it
GQ.au.handleInsertion = function(source, parseWord) {
    if (GQ.isContentEditable) {
        if (GQ.attachedIframe){ // we are in an iframe
            GQ.handleIframe(source, parseWord,
                function(params, result){
                    params['base'].data = result;
                    return result;
                },
                function(params, newCursorPos){
                    var range = params['iFrameDoc'].createRange();
                    range.setStart(params['base'], newCursorPos);
                    range.setEnd(params['base'], newCursorPos);
                    params['selection'].removeAllRanges();
                    params['selection'].addRange(range);
                }
            );
        } else { // in the 'new style' editor
            GQ.handleNewStyle(source, parseWord,
                function(params, result){
                    params['base'].data = result;
                    return result;
{'fraction_non_alphanumeric': 0.16523400191021967, 'fraction_numerical': 0.0015281757402101242, 'mean_word_length': 2.320964161116397, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '3924615', 'n_tokens_mistral': 3315, 'n_tokens_neox': 3224, 'n_words': 666}