<commit_before>define([
  'summernote/core/list',
  'summernote/core/dom',
  'summernote/core/agent'
], function (list, dom, agent) {
  var Clipboard = function (handler) {

    var $paste;

    this.attach = function (layoutInfo) {

      if (window.clipboardData || agent.isFF) {
        $paste = $('<div />').attr('contenteditable', true).css({
          position : 'absolute',
          left : -100000,
          'opacity' : 0
        });
        layoutInfo.editable().after($paste);
        $paste.on('paste', hPasteClipboardImage);
      }

      layoutInfo.editable().on('keydown', function (e) {
        if (e.ctrlKey && e.keyCode === 86) {
          if (window.clipboardData || agent.isFF) {
            handler.invoke('saveRange', layoutInfo.editable());
            if ($paste) {
              $paste.focus();
            }
          }
        }
      });

      layoutInfo.editable().on('paste', hPasteClipboardImage);
    };

    /**
     * paste clipboard image
     *
     * @param {Event} event
     */
    var hPasteClipboardImage = function (event) {

      var clipboardData = event.originalEvent.clipboardData;
      var layoutInfo = dom.makeLayoutInfo(event.currentTarget || event.target);
      var $editable = layoutInfo.editable();

      if (!clipboardData || !clipboardData.items || !clipboardData.items.length) {

        var callbacks = $editable.data('callbacks');
        // only can run if it has onImageUpload method
        if (!callbacks.onImageUpload) {
          return;
        }

        setTimeout(function () {
          if (!$paste) {
            return;
          }
          
          var imgNode = pasteDiv[0].firstChild;
          if (!imgNode) {
            return;
          }

          handler.invoke('restoreRange', $editable);
          if (!dom.isImg(imgNode)) {
            handler.invoke('pasteHTML', $editable, $paste.html());
          } else {
            var datauri = imgNode.src;

            var data = atob(datauri.split(',')[1]);
            var array = new Uint8Array(data.length);
            for (var i = 0; i < data.length; i++) {
              array[i] = data.charCodeAt(i);
            }

            var blob = new Blob([array], { type : 'image/png' });
            blob.name = 'clipboard.png';
            handler.invoke('focus', $editable);
            handler.insertImages(layoutInfo, [blob]);
          }

          $paste.html('');

        }, 0);

        return;
      }

      var item = list.head(clipboardData.items);
      var isClipboardImage = item.kind === 'file' && item.type.indexOf('image/') !== -1;

      if (isClipboardImage) {<commit_msg>remove $paste object<commit_after>define([
  'summernote/core/list',
  'summernote/core/dom',
  'summernote/core/agent'
], function (list, dom, agent) {
  var Clipboard = function (handler) {

    var $paste;

    this.attach = function (layoutInfo) {

      if (window.clipboardData || agent.isFF) {
        $paste = $('<div />').attr('contenteditable', true).css({
          position : 'absolute',
          left : -100000,
          'opacity' : 0
        });
        layoutInfo.editable().after($paste);
        $paste.on('paste', hPasteClipboardImage);
      }

      layoutInfo.editable().on('keydown', function (e) {
        if (e.ctrlKey && e.keyCode === 86) {
          if (window.clipboardData || agent.isFF) {
            handler.invoke('saveRange', layoutInfo.editable());
            if ($paste) {
              $paste.focus();
            }
          }
        }
      });

      layoutInfo.editable().on('paste', hPasteClipboardImage);
    };

    /**
     * paste clipboard image
     *
     * @param {Event} event
     */
    var hPasteClipboardImage = function (event) {

      var clipboardData = event.originalEvent.clipboardData;
      var layoutInfo = dom.makeLayoutInfo(event.currentTarget || event.target);
      var $editable = layoutInfo.editable();

      if (!clipboardData || !clipboardData.items || !clipboardData.items.length) {

        var callbacks = $editable.data('callbacks');
        // only can run if it has onImageUpload method
        if (!callbacks.onImageUpload) {
          return;
        }

        setTimeout(function () {
          if (!$paste) {
            return;
          }
          
          var imgNode = pasteDiv[0].firstChild;
          if (!imgNode) {
            return;
          }

          handler.invoke('restoreRange', $editable);
          if (!dom.isImg(imgNode)) {
            handler.invoke('pasteHTML', $editable, $paste.html());
          } else {
            var datauri = imgNode.src;

            var data = atob(datauri.split(',')[1]);
            var array = new Uint8Array(data.length);
            for (var i = 0; i < data.length; i++) {
              array[i] = data.charCodeAt(i);
            }

            var blob = new Blob([array], { type : 'image/png' });
            blob.name = 'clipboard.png';
            handler.invoke('focus', $editable);
            handler.insertImages(layoutInfo, [blob]);
          }

          $paste.remove();

        }, 0);

        return;
      }

      var item = list.head(clipboardData.items);
      var isClipboardImage = item.kind === 'file' && item.type.indexOf('image/') !== -1;

      if (isClipboardImage) {
{'fraction_non_alphanumeric': 0.1479020315169926, 'fraction_numerical': 0.005695842035314221, 'mean_word_length': 1.864600326264274, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4481980', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1538, 'n_words': 304}