<commit_before>class @Mercury.Regions.Full extends Mercury.Region
  # No IE < 10 support because those versions don't follow the W3C standards for HTML5 contentEditable (aka designMode).
  @supported: document.designMode && !jQuery.browser.konqueror && (!jQuery.browser.msie || (jQuery.browser.msie && parseFloat(jQuery.browser.version, 10) >= 10))
  @supportedText: "Chrome 10+, Firefox 4+, Safari 5+, Opera 11.64+"
  type = 'full'
  type: -> type

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


  build: ->
    # mozilla: set some initial content so everything works correctly
    @content('&nbsp;') if jQuery.browser.mozilla && @content() == ''

    # set overflow just in case
    @element.data({originalOverflow: @element.css('overflow')})
    @element.css({overflow: 'auto'})

    # mozilla: there's some weird behavior when the element isn't a div
    @specialContainer = jQuery.browser.mozilla && @element.get(0).tagName != 'DIV'

    # make it editable
    # mozilla: this makes double clicking in textareas fail: https://bugzilla.mozilla.org/show_bug.cgi?id=490367
    @element.get(0).contentEditable = true

    # make all snippets not editable, and set their versions to 1
    for element in @element.find('[data-snippet]')
      element.contentEditable = false
      jQuery(element).attr('data-version', '1')

    # add the basic editor settings to the document (only once)
    unless @document.mercuryEditing
      @document.mercuryEditing = true
      try
        @document.execCommand('styleWithCSS', false, false)
        @document.execCommand('insertBROnReturn', false, true)
        @document.execCommand('enableInlineTableEditing', false, false)
        @document.execCommand('enableObjectResizing', false, false)
      catch e
        # intentionally do nothing if any of these fail, to broaden support for Opera


  bindEvents: ->
    super

    Mercury.on 'region:update', =>
      return if @previewing || Mercury.region != @
      setTimeout((=> @selection().forceSelection(@element.get(0))), 1)
      currentElement = @currentElement()
      if currentElement.length
        # setup the table editor if we're inside a table
        table = currentElement.closest('table', @element)
        Mercury.tableEditor(table, currentElement.closest('tr, td'), '<br/>') if table.length
        # display a tooltip if we're in an anchor
        anchor = currentElement.closest('a', @element)
        if anchor.length && anchor.attr('href')
          Mercury.tooltip(anchor, "<a href=\"#{anchor.attr('href')}\" target=\"_blank\">#{anchor.attr('href')}</a>", {position: 'below'})
        else
          Mercury.tooltip.hide()

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

    @element.on 'dragover', (event) =>
      return if @previewing
      event.preventDefault() unless Mercury.snippet
      event.originalEvent.dataTransfer.dropEffect = 'copy'
      if jQuery.browser.webkit
        clearTimeout(@dropTimeout)
        @dropTimeout = setTimeout((=> @element.trigger('possible:drop')), 10)

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

      # handle dropping snippets
      clearTimeout(@dropTimeout)
      @dropTimeout = setTimeout((=> @element.trigger('possible:drop')), 1)

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

    # possible:drop custom event: we have to do this because webkit doesn't fire the drop event unless both dragover and
    # dragstart default behaviors are canceled.. but when we do that and observe the drop event, the default behavior
    # isn't handled (eg, putting the image where it was dropped,) so to allow the browser to do it's thing, and also do
    # our thing we have this little hack.  *sigh*
    # read: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html
    @element.on 'possible:drop', =>
      return if @previewing
      if snippetPlaceHolder = @element.find('img[data-snippet]').get(0)
        @focus()
        Mercury.Snippet.displayOptionsFor(jQuery(snippetPlaceHolder).data('snippet'), {}, jQuery(snippetPlaceHolder).data('options'))
        @document.execCommand('undo', false, null)

    # custom paste handling: we have to do some hackery to get the pasted content since it's not exposed normally
    # through a clipboard in firefox (heaven forbid), and to keep the behavior across all browsers, we manually detect
    # what was pasted by focusing a different (hidden) region, letting it paste there, making our adjustments, and then
    # inserting the content where it was intended.  This is possible, so it doesn't make sense why it wouldn't be
    # exposed in a sensible way.  *sigh*
    @element.on 'paste', (event) =>
      return if @previewing || Mercury.region != @
      if @specialContainer
        event.preventDefault()
        return
      return if @pasting
      Mercury.changes = true
      @handlePaste(event.originalEvent)

    @element.on 'focus', =>
      return if @previewing
      Mercury.region = @
      setTimeout((=> @selection().forceSelection(@element.get(0))), 1)
      Mercury.trigger('region:focused', {region: @})

    @element.on 'blur', =>
      return if @previewing
      Mercury.trigger('region:blurred', {region: @})
      Mercury.tooltip.hide()<commit_msg>Fixed inserting Snippet in Chrome bug (issue #362)<commit_after>class @Mercury.Regions.Full extends Mercury.Region
  # No IE < 10 support because those versions don't follow the W3C standards for HTML5 contentEditable (aka designMode).
  @supported: document.designMode && !jQuery.browser.konqueror && (!jQuery.browser.msie || (jQuery.browser.msie && parseFloat(jQuery.browser.version, 10) >= 10))
  @supportedText: "Chrome 10+, Firefox 4+, Safari 5+, Opera 11.64+"
  type = 'full'
  type: -> type

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


  build: ->
    # mozilla: set some initial content so everything works correctly
    @content('&nbsp;') if jQuery.browser.mozilla && @content() == ''

    # set overflow just in case
    @element.data({originalOverflow: @element.css('overflow')})
    @element.css({overflow: 'auto'})

    # mozilla: there's some weird behavior when the element isn't a div
    @specialContainer = jQuery.browser.mozilla && @element.get(0).tagName != 'DIV'

    # make it editable
    # mozilla: this makes double clicking in textareas fail: https://bugzilla.mozilla.org/show_bug.cgi?id=490367
    @element.get(0).contentEditable = true

    # make all snippets not editable, and set their versions to 1
    for element in @element.find('[data-snippet]')
      element.contentEditable = false
      jQuery(element).attr('data-version', '1')

    # add the basic editor settings to the document (only once)
    unless @document.mercuryEditing
      @document.mercuryEditing = true
      try
        @document.execCommand('styleWithCSS', false, false)
        @document.execCommand('insertBROnReturn', false, true)
        @document.execCommand('enableInlineTableEditing', false, false)
        @document.execCommand('enableObjectResizing', false, false)
      catch e
        # intentionally do nothing if any of these fail, to broaden support for Opera


  bindEvents: ->
    super

    Mercury.on 'region:update', =>
      return if @previewing || Mercury.region != @
      setTimeout((=> @selection().forceSelection(@element.get(0))), 1)
      currentElement = @currentElement()
      if currentElement.length
        # setup the table editor if we're inside a table
        table = currentElement.closest('table', @element)
        Mercury.tableEditor(table, currentElement.closest('tr, td'), '<br/>') if table.length
        # display a tooltip if we're in an anchor
        anchor = currentElement.closest('a', @element)
        if anchor.length && anchor.attr('href')
          Mercury.tooltip(anchor, "<a href=\"#{anchor.attr('href')}\" target=\"_blank\">#{anchor.attr('href')}</a>", {position: 'below'})
        else
          Mercury.tooltip.hide()

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

    @element.on 'dragover', (event) =>
      return if @previewing
      event.preventDefault() unless Mercury.snippet
      event.originalEvent.dataTransfer.dropEffect = 'copy'
      # removed to fix chrome update issue #362 https://github.com/jejacks0n/mercury/issues/362
      # if jQuery.browser.webkit
        # clearTimeout(@dropTimeout)
        # @dropTimeout = setTimeout((=> @element.trigger('possible:drop')), 10)

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

      # handle dropping snippets
      clearTimeout(@dropTimeout)
      @dropTimeout = setTimeout((=> @element.trigger('possible:drop')), 1)

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

    # possible:drop custom event: we have to do this because webkit doesn't fire the drop event unless both dragover and
    # dragstart default behaviors are canceled.. but when we do that and observe the drop event, the default behavior
    # isn't handled (eg, putting the image where it was dropped,) so to allow the browser to do it's thing, and also do
    # our thing we have this little hack.  *sigh*
    # read: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html
    @element.on 'possible:drop', =>
      return if @previewing
      if Mercury.snippet
        @focus()
        Mercury.Snippet.displayOptionsFor(Mercury.snippet.name, {}, Mercury.snippet.hasOptions)
        @document.execCommand('undo', false, null)

    # custom paste handling: we have to do some hackery to get the pasted content since it's not exposed normally
    # through a clipboard in firefox (heaven forbid), and to keep the behavior across all browsers, we manually detect
    # what was pasted by focusing a different (hidden) region, letting it paste there, making our adjustments, and then
    # inserting the content where it was intended.  This is possible, so it doesn't make sense why it wouldn't be
    # exposed in a sensible way.  *sigh*
    @element.on 'paste', (event) =>
      return if @previewing || Mercury.region != @
      if @specialContainer
        event.preventDefault()
        return
      return if @pasting
      Mercury.changes = true
      @handlePaste(event.originalEvent)

    @element.on 'focus', =>
      return if @previewing
      Mercury.region = @
      setTimeout((=> @selection().forceSelection(@element.get(0))), 1)
      Mercury.trigger('region:focused', {region: @})

    @element.on 'blur', =>
      return if @previewing
      Mercury.trigger('region:blurred', {region: @})
      Mercury.tooltip.hide()
{'fraction_non_alphanumeric': 0.11908616657672243, 'fraction_numerical': 0.00836481381543443, 'mean_word_length': 3.3723948092803777, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, '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': '1366389', 'n_tokens_mistral': 3231, 'n_tokens_neox': 3090, 'n_words': 951}