<commit_before>'use strict'

import React from 'react'
import ReactDOM from 'react-dom'
import Codemirror from 'medis-react-codemirror'
require('codemirror/mode/javascript/javascript')
require('codemirror/addon/lint/json-lint')
require('codemirror/addon/lint/lint')
require('codemirror/addon/selection/active-line')
require('codemirror/addon/edit/closebrackets')
require('codemirror/addon/edit/matchbrackets')
require('codemirror/addon/search/search')
require('codemirror/addon/search/searchcursor')
require('codemirror/addon/search/jump-to-line')
require('codemirror/addon/dialog/dialog')
require('codemirror/addon/dialog/dialog.css')
import jsonlint from 'jsonlint'
window.jsonlint = jsonlint.parser
require('codemirror/lib/codemirror.css')
require('codemirror/addon/lint/lint.css')
const msgpack = require('msgpack5')()

require('./index.scss')

class Editor extends React.PureComponent {
  constructor() {
    super()
    this.state = {
      currentMode: '',
      wrapping: true,
      changed: false,
      modes: {
        raw: false,
        json: false,
        messagepack: false
      }
    }
  }

  updateLayout() {
    const $this = $(ReactDOM.findDOMNode(this))
    if ($this.width() < 372) {
      $(ReactDOM.findDOMNode(this.refs.wrapSelector)).hide()
    } else {
      $(ReactDOM.findDOMNode(this.refs.wrapSelector)).show()
    }
    this.refs.codemirror.getCodeMirror().refresh()
  }

  componentDidMount() {
    this.updateLayoutBinded = this.updateLayout.bind(this)
    $(window).on('resize', this.updateLayoutBinded)
    this.init(this.props.buffer)
  }

  componentWillUnmount() {
    $(window).off('resize', this.updateLayoutBinded)
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.buffer !== this.props.buffer) {
      this.init(nextProps.buffer)
    }
  }

  init(buffer) {
    if (!buffer) {
      this.setState({currentMode: '', changed: false})
      return
    }
    const content = buffer.toString()
    const modes = {}
    modes.raw = content
    modes.json = tryFormatJSON(content, true)
    modes.messagepack = modes.json ? false : tryFormatMessagepack(buffer, true)
    let currentMode = 'raw'
    if (modes.messagepack) {<commit_msg>fix: content sometimes render badly<commit_after>'use strict'

import React from 'react'
import ReactDOM from 'react-dom'
import Codemirror from 'medis-react-codemirror'
require('codemirror/mode/javascript/javascript')
require('codemirror/addon/lint/json-lint')
require('codemirror/addon/lint/lint')
require('codemirror/addon/selection/active-line')
require('codemirror/addon/edit/closebrackets')
require('codemirror/addon/edit/matchbrackets')
require('codemirror/addon/search/search')
require('codemirror/addon/search/searchcursor')
require('codemirror/addon/search/jump-to-line')
require('codemirror/addon/dialog/dialog')
require('codemirror/addon/dialog/dialog.css')
import jsonlint from 'jsonlint'
window.jsonlint = jsonlint.parser
require('codemirror/lib/codemirror.css')
require('codemirror/addon/lint/lint.css')
const msgpack = require('msgpack5')()

require('./index.scss')

class Editor extends React.PureComponent {
  constructor() {
    super()

    this.resizeObserver = new ResizeObserver(() => {
      this.updateLayout()
    })

    this.state = {
      currentMode: '',
      wrapping: true,
      changed: false,
      modes: {
        raw: false,
        json: false,
        messagepack: false
      }
    }
  }

  updateLayout() {
    const {wrapSelector, codemirror} = this.refs

    const $this = $(ReactDOM.findDOMNode(this))
    if ($this.width() < 372) {
      $(ReactDOM.findDOMNode(wrapSelector)).hide()
    } else {
      $(ReactDOM.findDOMNode(wrapSelector)).show()
    }
    if (codemirror) {
      codemirror.getCodeMirror().refresh()
    }
  }

  componentDidMount() {
    this.init(this.props.buffer)
    this.resizeObserver.observe(ReactDOM.findDOMNode(this))
  }

  componentWillUnmount() {
    this.resizeObserver.disconnect()
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.buffer !== this.props.buffer) {
      this.init(nextProps.buffer)
    }
  }

  init(buffer) {
    if (!buffer) {
      this.setState({currentMode: '', changed: false})
      return
    }
    const content = buffer.toString()
    const modes = {}
    modes.raw = content
    modes.json = tryFormatJSON(content, true)
    modes.messagepack = modes.json ? false : tryFormatMessagepack(buffer, true)
    let currentMode = 'raw'
    if (modes.messagepack) {
{'fraction_non_alphanumeric': 0.14154535274356103, 'fraction_numerical': 0.0017917133258678612, 'mean_word_length': 3.7867095391211145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '6083439', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1468, 'n_words': 226}