<commit_before>define(function(require) {

  var _ = require('underscore');
  var $ = require('jquery');
  var Backbone = require('backbone');
  var utils = require('utils');
  require('autosize');


  var EditorView = Backbone.View.extend({

    el: '#editor',

    initialize: function(options) {

      _.bindAll(this, 'render', 'focus', 'blur', 'desktopFocus', 'handleCyrillic');

      this.model.on('change:id', this.render);
      this.model.on('change:content', this.handleCyrillic);
      this.model.on('update', this.render);

      this.$el.autosize();
    },

    // only re-render when content changed
    render: function() {
      var content = this.model.get('content');
      if ( content === this.$el.val() ) return;
      // strip html tags from documents.
      // this is just for migration from contenteditable to textarea.
      // we can remove this later on.
      content = content.replace(/<br>/ig,'\n').replace(/<[^>]+>/ig,'');
      this.$el.val(content || '').trigger('autosize.resize');
    },

    focus: function() {
      if (utils.isDesktop) return this.$el.focus();
      setTimeout(_.bind(this.$el.focus, this.$el), 500);
    },

    desktopFocus: function() {
      if (utils.isDesktop) this.focus();
    },

    blur: function() {
      this.$el.blur();
    },

    events: {
      'keyup': 'updateOpenDoc'
    },

    updateOpenDoc: function(e) {
      this.model.set( 'content', this.$el.val() );
    },

    // if a cyrillic doc is detected change to cyrillic font
    handleCyrillic: function(doc) {
      // see http://kourge.net/projects/regexp-unicode-block
      var isCyrillic = doc.get('content').match('[\u0400-\u04FF\u0500-\u052F]');
      if (!isCyrillic) return;
      this.$el.addClass('cyrillic');
      this.model.off(null, this.handleCyrillic);
    }

  });


  return EditorView;
});
<commit_msg>focus editor when switching docs on desktop<commit_after>define(function(require) {

  var _ = require('underscore');
  var $ = require('jquery');
  var Backbone = require('backbone');
  var utils = require('utils');
  require('autosize');


  var EditorView = Backbone.View.extend({

    el: '#editor',

    initialize: function(options) {

      _.bindAll(this, 'render', 'focus', 'blur', 'desktopFocus', 'handleCyrillic');

      this.model.on('change:id', this.render);
      this.model.on('change:content', this.handleCyrillic);
      this.model.on('update', this.render);

      this.$el.autosize();
    },

    // only re-render when content changed
    render: function() {
      var content = this.model.get('content');
      if ( content === this.$el.val() ) return;
      // strip html tags from documents.
      // this is just for migration from contenteditable to textarea.
      // we can remove this later on.
      content = content.replace(/<br>/ig,'\n').replace(/<[^>]+>/ig,'');
      this.$el.val(content || '').trigger('autosize.resize');
      this.desktopFocus();
    },

    focus: function() {
      if (utils.isDesktop) return this.$el.focus();
      setTimeout(_.bind(this.$el.focus, this.$el), 500);
    },

    desktopFocus: function() {
      if (utils.isDesktop) this.focus();
    },

    blur: function() {
      this.$el.blur();
    },

    events: {
      'keyup': 'updateOpenDoc'
    },

    updateOpenDoc: function(e) {
      this.model.set( 'content', this.$el.val() );
    },

    // if a cyrillic doc is detected change to cyrillic font
    handleCyrillic: function(doc) {
      // see http://kourge.net/projects/regexp-unicode-block
      var isCyrillic = doc.get('content').match('[\u0400-\u04FF\u0500-\u052F]');
      if (!isCyrillic) return;
      this.$el.addClass('cyrillic');
      this.model.off(null, this.handleCyrillic);
    }

  });


  return EditorView;
});

{'fraction_non_alphanumeric': 0.17742363877822045, 'fraction_numerical': 0.00849933598937583, 'mean_word_length': 2.800201816347124, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5406514', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1199, 'n_words': 247}