<commit_before>'use babel'

import Table from '../table'
import Colors from './colors'

import path from 'path'

const stopPropagationAndDefault = f => function (e) {
  e.stopPropagation()
  e.preventDefault()
  return f && f.call(this, e)
}

export default class MatrixTable extends Table {
  constructor(editor) {
    super(editor)

    this.subscriptions.add(this.tableElement.subscribeTo(this.tableElement.body, {
      'click': e => {
        const {metaKey, ctrlKey, shiftKey, pageX, pageY} = e
        const position = this.tableElement.cellPositionAtScreenPosition(pageX, pageY)
        const value = this.editor.getValueAtPosition(position)
        if (e.ctrlKey) {
          let splitDown = !e.shiftKey ? 'down' : ''
          let uri = path.normalize(atom.workspace.getActivePaneItem().getPath())
          let callPath = this.getCallPath(uri, value)
          console.log(value, callPath)
          this.openFile(callPath, splitDown)
        }

      }
    }))

    this.setCellRender()

    return
  }

  changeCursorPosition(e) {
    console.log(e)
  }

  setValue(e) {

  }

  openFile(uri, splitDown = false, data = {}) {
    let split = splitDown ? 'down' : ''
    atom.workspace.open(
      uri,
      {pending: true, split: split, activatePane: false, searchAllPanes: true, data : data}
    )
    atom.views.getView(atom.workspace).focus()
  }

  getCallPath(filename, callValue) {
    let dir = path.dirname(filename)
    if (callValue.indexOf(' ')) {
      let spaced = callValue.split(' ')
      callValue = spaced[0]
    }
    let parts = callValue.split('-')
    if (parts.length > 2) {
      return path.normalize(dir + '\\' + parts[2] + '.csv')
    }
  }

  setCellRender() {
    this.colors = new Colors(this.editor)
    table = this.editor.getTable()

    this.subscriptions.add(this.editor.onDidChangeModified(() => {
      console.log ('updated')
      this.editor.displayTable.updateScreenRows()
    }))
    let columns = this.editor.getScreenColumns()
    let self = this
    for (column in columns) {
      columns[column].cellRender = function(cell, position) {
        //console.log(cell.value, self.colors.make(cell.value, position[0], position[1]))
        return self.colors.make(cell.value, position[0], position[1])
      }
    }
  }<commit_msg>slash<commit_after>'use babel'

import Table from '../table'
import Colors from './colors'

import path from 'path'

const stopPropagationAndDefault = f => function (e) {
  e.stopPropagation()
  e.preventDefault()
  return f && f.call(this, e)
}

export default class MatrixTable extends Table {
  constructor(editor) {
    super(editor)

    this.subscriptions.add(this.tableElement.subscribeTo(this.tableElement.body, {
      'click': e => {
        const {metaKey, ctrlKey, shiftKey, pageX, pageY} = e
        const position = this.tableElement.cellPositionAtScreenPosition(pageX, pageY)
        const value = this.editor.getValueAtPosition(position)
        if (e.ctrlKey) {
          let splitDown = !e.shiftKey ? 'down' : ''
          let uri = path.normalize(atom.workspace.getActivePaneItem().getPath())
          let callPath = this.getCallPath(uri, value)
          console.log(value, callPath)
          this.openFile(callPath, splitDown)
        }

      }
    }))

    this.setCellRender()

    return
  }

  changeCursorPosition(e) {
    console.log(e)
  }

  setValue(e) {

  }

  openFile(uri, splitDown = false, data = {}) {
    let split = splitDown ? 'down' : ''
    atom.workspace.open(
      uri,
      {pending: true, split: split, activatePane: false, searchAllPanes: true, data : data}
    )
    atom.views.getView(atom.workspace).focus()
  }

  getCallPath(filename, callValue) {
    let dir = path.dirname(filename)
    if (callValue.indexOf(' ')) {
      let spaced = callValue.split(' ')
      callValue = spaced[0]
    }
    let parts = callValue.split('-')
    if (parts.length > 2) {
      return path.normalize(dir + '/' + parts[2] + '.csv')
    }
  }

  setCellRender() {
    this.colors = new Colors(this.editor)
    table = this.editor.getTable()

    this.subscriptions.add(this.editor.onDidChangeModified(() => {
      console.log ('updated')
      this.editor.displayTable.updateScreenRows()
    }))
    let columns = this.editor.getScreenColumns()
    let self = this
    for (column in columns) {
      columns[column].cellRender = function(cell, position) {
        //console.log(cell.value, self.colors.make(cell.value, position[0], position[1]))
        return self.colors.make(cell.value, position[0], position[1])
      }
    }
  }
{'fraction_non_alphanumeric': 0.13746985310238982, 'fraction_numerical': 0.0030695023021267264, 'mean_word_length': 2.81438127090301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4601367', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1442, 'n_words': 292}