<commit_before>'use strict';


const textarea_to_div = require('../_lib/textarea_to_div');


N.wire.once('init:mdedit', function () {

  function positionToRect(start, end) {
    let div = textarea_to_div(N.MDEdit.__textarea__);
    div.textContent = N.MDEdit.__textarea__.value;

    let range = document.createRange();
    range.setStart(div.childNodes[0], start);
    range.setEnd(div.childNodes[0], end);

    let divRect = div.getBoundingClientRect();
    let textRect = range.getBoundingClientRect();

    div.remove();

    return new DOMRect(textRect.x - divRect.x, textRect.y - divRect.y, textRect.width, textRect.height);
  }

  // Init emojis select popup.
  //
  // Behaviour:
  //
  // - show when
  //   - ':' typed at start of line or after space
  //   - backspace typed and string before cursor finished to emoji start
  // - hide when
  //   - escape pressed
  //   - editor lost focus
  //   - cursor position changed
  // - apply when
  //   - enter or right arrow pressed
  //   - click by emoji
  //
  N.wire.on('mdedit:init', function initEmojis() {
    let $popup = N.MDEdit.__layout__.find('.emoji-autocomplete');

    // To check emoji start at line end (and extract emoji text)
    let emojiAtEndRE = /(?:^|\s):([^:\s]*)$/;


    // Show or update popup
    //
    function showPopup(text) {
      let emojis = {};

      // Filter emijis by text (but not more than 5)
      for (let [ name, val ] of Object.entries(N.MDEdit.emojis.named)) {
        if (name.indexOf(text) !== -1) {
          emojis[name] = val;
        } else {
          continue;
        }

        if (Object.keys(emojis).length >= 5) break;
      }

      // If nothing found - hide popup
      if (Object.keys(emojis).length === 0) {
        $popup.removeClass('emoji-autocomplete__m-visible');<commit_msg>mdedit: check start only in emoji autocomplete<commit_after>'use strict';


const textarea_to_div = require('../_lib/textarea_to_div');


N.wire.once('init:mdedit', function () {

  function positionToRect(start, end) {
    let div = textarea_to_div(N.MDEdit.__textarea__);
    div.textContent = N.MDEdit.__textarea__.value;

    let range = document.createRange();
    range.setStart(div.childNodes[0], start);
    range.setEnd(div.childNodes[0], end);

    let divRect = div.getBoundingClientRect();
    let textRect = range.getBoundingClientRect();

    div.remove();

    return new DOMRect(textRect.x - divRect.x, textRect.y - divRect.y, textRect.width, textRect.height);
  }

  // Init emojis select popup.
  //
  // Behaviour:
  //
  // - show when
  //   - ':' typed at start of line or after space
  //   - backspace typed and string before cursor finished to emoji start
  // - hide when
  //   - escape pressed
  //   - editor lost focus
  //   - cursor position changed
  // - apply when
  //   - enter or right arrow pressed
  //   - click by emoji
  //
  N.wire.on('mdedit:init', function initEmojis() {
    let $popup = N.MDEdit.__layout__.find('.emoji-autocomplete');

    // To check emoji start at line end (and extract emoji text)
    let emojiAtEndRE = /(?:^|\s):([^:\s]*)$/;


    // Show or update popup
    //
    function showPopup(text) {
      let emojis = {};

      // Filter emijis by text (but not more than 5)
      for (let [ name, val ] of Object.entries(N.MDEdit.emojis.named)) {
        if (name.startsWith(text)) {
          emojis[name] = val;
        } else {
          continue;
        }

        if (Object.keys(emojis).length >= 5) break;
      }

      // If nothing found - hide popup
      if (Object.keys(emojis).length === 0) {
        $popup.removeClass('emoji-autocomplete__m-visible');
{'fraction_non_alphanumeric': 0.14254325734688272, 'fraction_numerical': 0.0030211480362537764, 'mean_word_length': 2.4037383177570093, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6609908', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1206, 'n_words': 294}