<commit_before># todo:
# context for the toolbar buttons and groups needs to change so we can do the following:
# how to handle context for buttons?  if the cursor is within a bold area (**bo|ld**), or selecting it -- it would be
# nice if we could activate the bold button for instance.

class @Mercury.Regions.Simple extends Mercury.Region
  @supported: document.getElementById
  @supportedText: "IE 7+, Chrome 10+, Firefox 4+, Safari 5+, Opera 8+"

  type = 'simple'

  constructor: (@element, @window, @options = {}) ->
    @type = 'simple'
    super


  build: ->
    width = '100%'
    height = @element.height()

    value = @element.text()
    @element.removeClass(Mercury.config.regions.className)
    @textarea = jQuery('<textarea>', @document).val(value)
    @textarea.attr('class', @element.attr('class')).addClass('mercury-textarea')
    @textarea.css
      border: 0
      background: 'transparent'
      display: 'block'
      'overflow-y': 'hidden'
      width: width
      height: height
      fontFamily: 'inherit'
      fontSize: 'inherit'
      fontWeight: 'inherit'
      fontStyle: 'inherit'
      color: 'inherit'
    @element.addClass(Mercury.config.regions.className)
    @element.empty().append(@textarea)

    @container = @element
    @container.data('region', @)
    @element = @textarea
    @resize()


  bindEvents: ->
    Mercury.on 'mode', (event, options) => @togglePreview() if options.mode == 'preview'
    Mercury.on 'focus:frame', => @focus() if !@previewing && Mercury.region == @

    Mercury.on 'action', (event, options) =>
      return if @previewing || Mercury.region != @
      @execCommand(options.action, options) if options.action

    Mercury.on 'unfocus:regions', =>
      return if @previewing || Mercury.region != @
      @element.blur()
      @container.removeClass('focus')
      Mercury.trigger('region:blurred', {region: @})

    @element.on 'dragenter', (event) =>
      return if @previewing
      event.preventDefault()
      event.originalEvent.dataTransfer.dropEffect = 'copy'

    @element.on 'dragover', (event) =>
      return if @previewing
      event.preventDefault()
      event.originalEvent.dataTransfer.dropEffect = 'copy'

    @element.on 'drop', (event) =>
      return if @previewing

      # handle dropping snippets
      if Mercury.snippet
        event.preventDefault()
        @focus()
        Mercury.Snippet.displayOptionsFor(Mercury.snippet)

      # handle any files that were dropped
      if event.originalEvent.dataTransfer.files.length
        event.preventDefault()
        @focus()
        Mercury.uploader(event.originalEvent.dataTransfer.files[0])

    @element.on 'focus', =>
      return if @previewing
      Mercury.region = @
      @container.addClass('focus')
      Mercury.trigger('region:focused', {region: @})

    @element.on 'keydown', (event) =>
      return if @previewing
      @resize()
      switch event.keyCode
        when 90 # undo / redo
          return unless event.metaKey
          event.preventDefault()
          if event.shiftKey then @execCommand('redo') else @execCommand('undo')
          return

        when 13 # enter or return
          selection = @selection()
          text = @element.val()
          start = text.lastIndexOf('\n', selection.start)
          end = text.indexOf('\n', selection.end)
          end = text.length if end < start
          start = text.lastIndexOf('\n', selection.start - 1) if text[start] == '\n'
          if text[start + 1] == '-'
            selection.replace('\n- ', false, true)
          if /\d/.test(text[start + 1])
            lineText = text.substring(start, end)
            if /(\d+)\./.test(lineText)
              number = parseInt(RegExp.$1)
              selection.replace("\n#{number += 1}. ", false, true)
          # Never allow return. Newlines won't survive the 
          # change-over to HTML, so just don't encourage their
          # use.
          event.preventDefault()

        when 9 # tab
          event.preventDefault()
          @execCommand('insertHTML', {value: '  '})

      if event.metaKey
        switch event.keyCode
          when 66 # b
            @execCommand('bold')
            event.preventDefault()

          when 73 # i
            @execCommand('italic')
            event.preventDefault()

          when 85 # u
            @execCommand('underline')
            event.preventDefault()

      @pushHistory(event.keyCode)

    @element.on 'keyup', =>
      return if @previewing
      Mercury.changes = true
      @resize()
      Mercury.trigger('region:update', {region: @})

    @element.on 'mouseup', =>
      return if @previewing
      @focus()
      Mercury.trigger('region:focused', {region: @})

    @element.on 'paste', (event) =>
      return if @previewing || Mercury.region != @
      if @specialContainer
        event.preventDefault()
        return
      return if @pasting
      Mercury.changes = true
      @handlePaste(event.originalEvent)


  handlePaste: (event) ->
    # get the text content from the clipboard and fall back to using the sanitizer if unavailable
    @execCommand('insertHTML', {value: event.clipboardData.getData('text/plain').replace(/\n/g, ' ')})
    event.preventDefault()
    return


  focus: ->
    @element.focus()


  content: (value = null, filterSnippets = true) ->
    if value != null
      if jQuery.type(value) == 'string'
        @element.val(value)
      else
        @element.val(value.html)
        @selection().select(value.selection.start, value.selection.end)
    else
      return @element.val()

<commit_msg>Add path for simple fields<commit_after># todo:
# context for the toolbar buttons and groups needs to change so we can do the following:
# how to handle context for buttons?  if the cursor is within a bold area (**bo|ld**), or selecting it -- it would be
# nice if we could activate the bold button for instance.

class @Mercury.Regions.Simple extends Mercury.Region
  @supported: document.getElementById
  @supportedText: "IE 7+, Chrome 10+, Firefox 4+, Safari 5+, Opera 8+"

  type = 'simple'

  constructor: (@element, @window, @options = {}) ->
    @type = 'simple'
    super


  build: ->
    width = '100%'
    height = @element.height()

    value = @element.text()
    @element.removeClass(Mercury.config.regions.className)
    @textarea = jQuery('<textarea>', @document).val(value)
    @textarea.attr('class', @element.attr('class')).addClass('mercury-textarea')
    @textarea.css
      border: 0
      background: 'transparent'
      display: 'block'
      'overflow-y': 'hidden'
      width: width
      height: height
      fontFamily: 'inherit'
      fontSize: 'inherit'
      fontWeight: 'inherit'
      fontStyle: 'inherit'
      color: 'inherit'
    @element.addClass(Mercury.config.regions.className)
    @element.empty().append(@textarea)

    @container = @element
    @container.data('region', @)
    @element = @textarea
    @resize()


  bindEvents: ->
    Mercury.on 'mode', (event, options) => @togglePreview() if options.mode == 'preview'
    Mercury.on 'focus:frame', => @focus() if !@previewing && Mercury.region == @

    Mercury.on 'action', (event, options) =>
      return if @previewing || Mercury.region != @
      @execCommand(options.action, options) if options.action

    Mercury.on 'unfocus:regions', =>
      return if @previewing || Mercury.region != @
      @element.blur()
      @container.removeClass('focus')
      Mercury.trigger('region:blurred', {region: @})

    @element.on 'dragenter', (event) =>
      return if @previewing
      event.preventDefault()
      event.originalEvent.dataTransfer.dropEffect = 'copy'

    @element.on 'dragover', (event) =>
      return if @previewing
      event.preventDefault()
      event.originalEvent.dataTransfer.dropEffect = 'copy'

    @element.on 'drop', (event) =>
      return if @previewing

      # handle dropping snippets
      if Mercury.snippet
        event.preventDefault()
        @focus()
        Mercury.Snippet.displayOptionsFor(Mercury.snippet)

      # handle any files that were dropped
      if event.originalEvent.dataTransfer.files.length
        event.preventDefault()
        @focus()
        Mercury.uploader(event.originalEvent.dataTransfer.files[0])

    @element.on 'focus', =>
      return if @previewing
      Mercury.region = @
      @container.addClass('focus')
      Mercury.trigger('region:focused', {region: @})

    @element.on 'keydown', (event) =>
      return if @previewing
      @resize()
      switch event.keyCode
        when 90 # undo / redo
          return unless event.metaKey
          event.preventDefault()
          if event.shiftKey then @execCommand('redo') else @execCommand('undo')
          return

        when 13 # enter or return
          selection = @selection()
          text = @element.val()
          start = text.lastIndexOf('\n', selection.start)
          end = text.indexOf('\n', selection.end)
          end = text.length if end < start
          start = text.lastIndexOf('\n', selection.start - 1) if text[start] == '\n'
          if text[start + 1] == '-'
            selection.replace('\n- ', false, true)
          if /\d/.test(text[start + 1])
            lineText = text.substring(start, end)
            if /(\d+)\./.test(lineText)
              number = parseInt(RegExp.$1)
              selection.replace("\n#{number += 1}. ", false, true)
          # Never allow return. Newlines won't survive the 
          # change-over to HTML, so just don't encourage their
          # use.
          event.preventDefault()

        when 9 # tab
          event.preventDefault()
          @execCommand('insertHTML', {value: '  '})

      if event.metaKey
        switch event.keyCode
          when 66 # b
            @execCommand('bold')
            event.preventDefault()

          when 73 # i
            @execCommand('italic')
            event.preventDefault()

          when 85 # u
            @execCommand('underline')
            event.preventDefault()

      @pushHistory(event.keyCode)

    @element.on 'keyup', =>
      return if @previewing
      Mercury.changes = true
      @resize()
      Mercury.trigger('region:update', {region: @})

    @element.on 'mouseup', =>
      return if @previewing
      @focus()
      Mercury.trigger('region:focused', {region: @})

    @element.on 'paste', (event) =>
      return if @previewing || Mercury.region != @
      if @specialContainer
        event.preventDefault()
        return
      return if @pasting
      Mercury.changes = true
      @handlePaste(event.originalEvent)


  handlePaste: (event) ->
    # get the text content from the clipboard and fall back to using the sanitizer if unavailable
    @execCommand('insertHTML', {value: event.clipboardData.getData('text/plain').replace(/\n/g, ' ')})
    event.preventDefault()
    return


  path: ->
    [@container.get(0)]


  focus: ->
    @element.focus()


  content: (value = null, filterSnippets = true) ->
    if value != null
      if jQuery.type(value) == 'string'
        @element.val(value)
      else
        @element.val(value.html)
        @selection().select(value.selection.start, value.selection.end)
    else
      return @element.val()


{'fraction_non_alphanumeric': 0.1327441528298518, 'fraction_numerical': 0.004909837529012676, 'mean_word_length': 2.442839582052858, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 42, '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': '5009756', 'n_tokens_mistral': 3300, 'n_tokens_neox': 3191, 'n_words': 808}