<commit_before>if (typeof define !== 'function') { var define = require('amdefine')(module) }
define( function(require,exports,module){

  /*

   #TableView

   An interactive table interface for a single sheet.

   ## References
   * Sheet
   * SelectionCollection
   */

  var $ = require('jquery');
  var t = require('../templates');
  var RefBinder = require('ref-binder');
  var View = require('backbone').View;
  var ColMenuView = require('./col_menu');
  var RowMenuView = require('./row_menu');
  /*Isislab*/
  var CellMenuView = require('./cell_menu');
  /*and Isislab*/
  var _ = require('underscore');
  var h = require('es_client/helpers');

  var MIN_CELL_WIDTH = 22;
  var MIN_CELL_HEIGHT = 22;

  var Table = module.exports = View.extend({


// ## DOM BINDING

    events: {
      'mousedown .es-table-cell': 'cellMouseDown',
      'mousemove .es-table-cell': 'cellMouseMove',
      'mouseup .es-table-cell': 'cellMouseUp',
      'dblclick .es-table-cell': 'cellClicked',
      'click .es-row-header': 'showRowMenu',
      'click .es-column-header': 'showColMenu',
      /*isislab*/
      'mousedown .es-table-cell': 'showCellMenu',
      /*and isislab*/
      'contextmenu .es-column-header': 'showColMenu',
      'contextmenu .es-row-header': 'showRowMenu',
      'change .es-table-cell-input': 'changeCell',
      'keydown': 'inputKeypress',
      //CELLS SELECTION FEATURE
      'mousedown .es-table-cell': 'cellsSelectionMousedown',
      'mouseover .es-table-cell': 'cellsSelectionMouseover',
      'mouseup .es-table-cell'  : 'cellsSelectionMouseup'
    },

//CELLS SELECRION FEATURE

    selectTo: function(cell) {

      //var row = cell.parent();
      var cellIndex = cell.index();
      cellIndex = (cellIndex < 0) ? this.startCellIndex : cellIndex;
      var rowIndex = cell.parent().index();
      rowIndex = (rowIndex < 0) ? this.startRowIndex : rowIndex;


      //var rowStart, rowEnd, cellStart, cellEnd;

      if (rowIndex < this.startRowIndex) {
        this.rowStart = rowIndex;
        this.rowEnd = this.startRowIndex;
      } else {
        this.rowStart = this.startRowIndex;
        this.rowEnd = rowIndex;
      }

      if (cellIndex < this.startCellIndex) {
        this.cellStart = cellIndex;
        this.cellEnd = this.startCellIndex;
      } else {
        this.cellStart = this.startCellIndex;
        this.cellEnd = cellIndex;
      }

      for (var i = this.rowStart; i <= this.rowEnd; i++) {
        var rowCells = $('#es-grid-'+this.getId()).find("tr").eq(i).find("td");
        for (var j = this.cellStart; j <= this.cellEnd; j++) {
          rowCells.eq(j).addClass("cpselected");
        }
      }
      //console.log("rowStart: " + rowStart + " rowEnd: " + rowEnd + " cellStart: " + cellStart + " cellEnd: " + cellEnd );
    },

    cellsSelectionMousedown: function(e){
      this.setCellDragTarget(e);
      if (this.isDraggingCell()){
        return false;
      }

      if(e.which == 3){
        $('#es-grid-'+this.getId()).find(".cpselected").removeClass("cpselected"); // deselect everything
        this.showCellMenu(e);
        return false;
      }

      this.clearOverlays();
      this.isMouseDown = true;
      this.editingCell = false;
      this.current_cell = $(e.currentTarget);

      $('#es-grid-'+this.getId()).find(".cpselected").removeClass("cpselected"); // deselect everything

      if (e.shiftKey) {
        this.selectTo(cell);
      } else {
        this.current_cell.addClass("cpselected");
        this.cellIndex = this.startCellIndex = this.current_cell.index();
        this.rowIndex  = this.startRowIndex  = this.current_cell.parent().index();
      }
      return true; // prevent text selection
    },

    cellsSelectionMouseover: function(e){
      if (!this.isMouseDown) return;
      $('#es-grid-'+this.getId()).find(".cpselected").removeClass("cpselected");
      //this.selectTo($(this));
      this.selectTo($(e.currentTarget));
    },

    cellsSelectionMouseup: function(e){
      if(this.isDraggingCell()) this.cellMouseUp(e);
      this.isMouseDown = false;
    },

    //Keypress when cell in not active. Just for copy & paste feature.
    cellsSelectionKeydown: function(e){
      if(_this.editingCell == true){
        $('textarea')._onKeyDown(e);
        return false;
      }

      var code = (e.keyCode ? e.keyCode : e.which);
      var cells = _this.getLocalSelection().getCells();
      _.each(cells, function(cell){
        _this.getSheet().commitCell(cell.row_id.toString(), cell.col_id.toString());
      }, _this);

      var cell = null;
      var sheet_table =  $('#es-grid-'+_this.getId());
      sheet_table.find(".cpselected").removeClass("cpselected");
      switch(code){
        case 37://LEFT ARROW
          cell = sheet_table.find("tr").eq(_this.rowIndex).find("td").eq((_this.cellIndex < 0) ? 0 : --_this.cellIndex);
          break;
        case 38://UP ARROW
          cell = sheet_table.find("tr").eq((_this.rowIndex < 0) ? 0 :  --_this.rowIndex).find("td").eq(_this.cellIndex);
          break;
        case 39://RIGHT ARROW
          cell = sheet_table.find("tr").eq(_this.rowIndex).find("td").eq(++_this.cellIndex);
          break;
        case 40://DOWN ARROW
          cell = sheet_table.find("tr").eq(++_this.rowIndex).find("td").eq(_this.cellIndex);
          break;
        case 13://enter
          if (_this.isDraggingCell()) return;
          cell = sheet_table.find("tr").eq(_this.rowIndex).find("td").eq(_this.cellIndex);
          _this.clearOverlays();
          _this.getLocalSelection().addCell(_this.getSheet().id,$(cell).data().row_id.toString(),$(cell).data().col_id.toString());
          _this.current_cell = cell;
          _this.editingCell = true;
          break;
      }

      if (e.shiftKey) {
        _this.selectTo(cell);
      } else {
        _this.current_cell = cell;
        _this.current_cell.addClass("cpselected");
        _this.startCellIndex = _this.cellIndex;
        _this.startRowIndex  = _this.rowIndex;
      }
<commit_msg>Provide copy and paste in ethersheet.<commit_after>if (typeof define !== 'function') { var define = require('amdefine')(module) }
define( function(require,exports,module){

  /*

   #TableView

   An interactive table interface for a single sheet.

   ## References
   * Sheet
   * SelectionCollection
   */

  var $ = require('jquery');
  var t = require('../templates');
  var RefBinder = require('ref-binder');
  var View = require('backbone').View;
  var ColMenuView = require('./col_menu');
  var RowMenuView = require('./row_menu');
  /*Isislab*/
  var CellMenuView = require('./cell_menu');
  /*and Isislab*/
  var _ = require('underscore');
  var h = require('es_client/helpers');

  var MIN_CELL_WIDTH = 22;
  var MIN_CELL_HEIGHT = 22;

  var Table = module.exports = View.extend({


// ## DOM BINDING

    events: {
      'mousedown .es-table-cell': 'cellMouseDown',
      'mousemove .es-table-cell': 'cellMouseMove',
      'mouseup .es-table-cell': 'cellMouseUp',
      'dblclick .es-table-cell': 'cellClicked',
      'click .es-row-header': 'showRowMenu',
      'click .es-column-header': 'showColMenu',
      /*isislab*/
      'mousedown .es-table-cell': 'showCellMenu',
      /*and isislab*/
      'contextmenu .es-column-header': 'showColMenu',
      'contextmenu .es-row-header': 'showRowMenu',
      'change .es-table-cell-input': 'changeCell',
      'keydown': 'inputKeypress',
      //CELLS SELECTION FEATURE
      'mousedown .es-table-cell': 'cellsSelectionMousedown',
      'mouseover .es-table-cell': 'cellsSelectionMouseover',
      'mouseup .es-table-cell'  : 'cellsSelectionMouseup'
    },

//CELLS SELECRION FEATURE

    selectTo: function(cell) {

      //var row = cell.parent();
      var cellIndex = cell.index();
      cellIndex = (cellIndex < 0) ? this.startCellIndex : cellIndex;
      var rowIndex = cell.parent().index();
      rowIndex = (rowIndex < 0) ? this.startRowIndex : rowIndex;


      //var rowStart, rowEnd, cellStart, cellEnd;

      if (rowIndex < this.startRowIndex) {
        this.rowStart = rowIndex;
        this.rowEnd = this.startRowIndex;
      } else {
        this.rowStart = this.startRowIndex;
        this.rowEnd = rowIndex;
      }

      if (cellIndex < this.startCellIndex) {
        this.cellStart = cellIndex;
        this.cellEnd = this.startCellIndex;
      } else {
        this.cellStart = this.startCellIndex;
        this.cellEnd = cellIndex;
      }

      for (var i = this.rowStart; i <= this.rowEnd; i++) {
        var rowCells = $('#es-grid-'+this.getId()).find("tr").eq(i).find("td");
        for (var j = this.cellStart; j <= this.cellEnd; j++) {
          rowCells.eq(j).addClass("cpselected");
        }
      }
      //console.log("rowStart: " + rowStart + " rowEnd: " + rowEnd + " cellStart: " + cellStart + " cellEnd: " + cellEnd );
    },

    cellsSelectionMousedown: function(e){
      this.setCellDragTarget(e);
      if (this.isDraggingCell()){
        return false;
      }

      if(e.which == 3){
        $('#es-grid-'+this.getId()).find(".cpselected").removeClass("cpselected"); // deselect everything
        this.showCellMenu(e);
        return false;
      }

      this.clearOverlays();
      this.isMouseDown = true;
      this.editingCell = false;
      this.current_cell = $(e.currentTarget);

      $('#es-grid-'+this.getId()).find(".cpselected").removeClass("cpselected"); // deselect everything

      if (e.shiftKey) {
        this.selectTo(cell);
      } else {
        this.current_cell.addClass("cpselected");
        this.cellIndex = this.startCellIndex = this.current_cell.index();
        this.rowIndex  = this.startRowIndex  = this.current_cell.parent().index();
        this.rowEnd = this.startRowIndex;
        this.cellEnd = this.startCellIndex;
      }
      return true; // prevent text selection
    },

    cellsSelectionMouseover: function(e){
      if (!this.isMouseDown) return;
      $('#es-grid-'+this.getId()).find(".cpselected").removeClass("cpselected");
      //this.selectTo($(this));
      this.selectTo($(e.currentTarget));
    },

    cellsSelectionMouseup: function(e){
      if(this.isDraggingCell()) this.cellMouseUp(e);
      this.isMouseDown = false;
    },

    //Keypress when cell in not active. Just for copy & paste feature.
    cellsSelectionKeydown: function(e){
      if(_this.editingCell == true){
        $('textarea')._onKeyDown(e);
        return false;
      }

      var code = (e.keyCode ? e.keyCode : e.which);
      var cells = _this.getLocalSelection().getCells();
      _.each(cells, function(cell){
        _this.getSheet().commitCell(cell.row_id.toString(), cell.col_id.toString());
      }, _this);

      var cell = null;
      var sheet_table =  $('#es-grid-'+_this.getId());
      sheet_table.find(".cpselected").removeClass("cpselected");
      switch(code){
        case 37://LEFT ARROW
          cell = sheet_table.find("tr").eq(_this.rowIndex).find("td").eq((_this.cellIndex < 0) ? 0 : --_this.cellIndex);
          break;
        case 38://UP ARROW
          cell = sheet_table.find("tr").eq((_this.rowIndex < 0) ? 0 :  --_this.rowIndex).find("td").eq(_this.cellIndex);
          break;
        case 39://RIGHT ARROW
          cell = sheet_table.find("tr").eq(_this.rowIndex).find("td").eq(++_this.cellIndex);
          break;
        case 40://DOWN ARROW
          cell = sheet_table.find("tr").eq(++_this.rowIndex).find("td").eq(_this.cellIndex);
          break;
        case 13://enter
          if (_this.isDraggingCell()) return;
          cell = sheet_table.find("tr").eq(_this.rowIndex).find("td").eq(_this.cellIndex);
          _this.clearOverlays();
          _this.getLocalSelection().addCell(_this.getSheet().id,$(cell).data().row_id.toString(),$(cell).data().col_id.toString());
          _this.current_cell = cell;
          _this.editingCell = true;
          break;
      }

      if (e.shiftKey) {
        _this.selectTo(cell);
      } else {
        _this.current_cell = cell;
        _this.current_cell.addClass("cpselected");
        _this.startCellIndex = _this.cellIndex;
        _this.startRowIndex  = _this.rowIndex;
        _this.rowEnd = _this.startRowIndex;
        _this.cellEnd = _this.startCellIndex;
      }

{'fraction_non_alphanumeric': 0.16063237221494103, 'fraction_numerical': 0.0034403669724770644, 'mean_word_length': 2.5835045494570004, 'pattern_counts': {'":': 0, '<': 19, '<?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': '1873568', 'n_tokens_mistral': 3959, 'n_tokens_neox': 3850, 'n_words': 687}