<commit_before>window.Style = function(templates, cwd, style) {

var map;
var baselayer;
var tiles;
var xray;
var grids;
var gridc;
var templateEditor;
var mtime = (+new Date).toString(36);

statHandler('drawtime')();

if ('onbeforeunload' in window) window.onbeforeunload = function() {
  if (Editor && Editor.changed) return 'Save your changes?';
};

var Editor = Backbone.View.extend({});
var Modal = new views.Modal({
  el: $('.modal-content'),
  templates: templates
});

var Tab = function(id, value) {
  var tab = CodeMirror(function(cm) {
    document.getElementById('code')
      .insertBefore(cm, document.getElementById('interactivity'));
  }, {
    value: value,
    lineNumbers: true,
    paletteHints: true,
    gutters: ['CodeMirror-linenumbers', 'errors'],
    mode: {
      name: 'carto',
      reference: window.cartoRef
    }
  });
  var completer = cartoCompletion(tab, window.cartoRef);

  /*
  @TODO
  function updateSelectors(model) {
      var ids = _.map(model.get('Layer').pluck('id'),
          function(x) { return '#' + x; });
      var classes = _(model.get('Layer').pluck('class')).chain().map(
          function(c) {
              if (c == undefined) return '';
              var cs = c.split(' ');
              if (cs[0] == '') return '';
              return _.map(cs, function(x) { return '.' + x; });
          }).flatten().compact().value();
      cartoCompleter.ids(ids);
      cartoCompleter.classes(classes);
  }
  this.model.bind('change', updateSelectors);
  updateSelectors(this.model);
  */

  function changed() {
    Editor.changed = true;
  }

  if (id === 'template') templateEditor = tab;
  tab.on('keydown', completer.onKeyEvent);
  tab.on('change', changed);
  tab.setOption('onHighlightComplete', _(completer.setTitles).throttle(100));
  tab.getWrapperElement().id = 'code-' + id.replace(/[^\w+]/g,'_');
  return tab;
};
var code = _(style.styles).reduce(function(memo, value, k) {
  memo[k] = Tab(k, value);
  return memo;
}, {});

// Add in interactivity template. 
code.template = Tab('template', style.template);

_(code).toArray().shift().getWrapperElement().className += ' active';

var Style = Backbone.Model.extend({});
Style.prototype.url = function() { return '/style.json?id=' + this.get('id'); };

var Source = Backbone.Model.extend({});
Source.prototype.url = function() { return '/source.json?id=' + this.get('id'); };

Editor.prototype.events = {
  'click .js-browsestyle': 'browseStyle',<commit_msg>in carto editor, read tabs as two spaces<commit_after>window.Style = function(templates, cwd, style) {

var map;
var baselayer;
var tiles;
var xray;
var grids;
var gridc;
var templateEditor;
var mtime = (+new Date).toString(36);

statHandler('drawtime')();

if ('onbeforeunload' in window) window.onbeforeunload = function() {
  if (Editor && Editor.changed) return 'Save your changes?';
};

var Editor = Backbone.View.extend({});
var Modal = new views.Modal({
  el: $('.modal-content'),
  templates: templates
});

CodeMirror.keyMap.tabSpace = {
  Tab: function(cm) {
    var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
    cm.replaceSelection(spaces, 'end', '+input');
  },
  fallthrough: ['default']
};

var Tab = function(id, value) {
  var tab = CodeMirror(function(cm) {
    document.getElementById('code')
      .insertBefore(cm, document.getElementById('interactivity'));
  }, {
    value: value,
    lineNumbers: true,
    paletteHints: true,
    gutters: ['CodeMirror-linenumbers', 'errors'],
    mode: {
      name: 'carto',
      reference: window.cartoRef
    },
    keyMap: 'tabSpace'
  });
  var completer = cartoCompletion(tab, window.cartoRef);

  /*
  @TODO
  function updateSelectors(model) {
      var ids = _.map(model.get('Layer').pluck('id'),
          function(x) { return '#' + x; });
      var classes = _(model.get('Layer').pluck('class')).chain().map(
          function(c) {
              if (c == undefined) return '';
              var cs = c.split(' ');
              if (cs[0] == '') return '';
              return _.map(cs, function(x) { return '.' + x; });
          }).flatten().compact().value();
      cartoCompleter.ids(ids);
      cartoCompleter.classes(classes);
  }
  this.model.bind('change', updateSelectors);
  updateSelectors(this.model);
  */

  function changed() {
    Editor.changed = true;
  }

  if (id === 'template') templateEditor = tab;
  tab.on('keydown', completer.onKeyEvent);
  tab.on('change', changed);
  tab.setOption('onHighlightComplete', _(completer.setTitles).throttle(100));
  tab.getWrapperElement().id = 'code-' + id.replace(/[^\w+]/g,'_');
  return tab;
};
var code = _(style.styles).reduce(function(memo, value, k) {
  memo[k] = Tab(k, value);
  return memo;
}, {});

// Add in interactivity template.
code.template = Tab('template', style.template);

_(code).toArray().shift().getWrapperElement().className += ' active';

var Style = Backbone.Model.extend({});
Style.prototype.url = function() { return '/style.json?id=' + this.get('id'); };

var Source = Backbone.Model.extend({});
Source.prototype.url = function() { return '/source.json?id=' + this.get('id'); };

Editor.prototype.events = {
  'click .js-browsestyle': 'browseStyle',
{'fraction_non_alphanumeric': 0.18601964182553438, 'fraction_numerical': 0.002503369921047564, 'mean_word_length': 3.584289496910856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '856306', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1686, 'n_words': 356}