<commit_before>#
#= require_tree .
#= require ace/ace
#= require ace/mode-ruby
#= require ace/theme-monokai
#= require ace/theme-github

window.rails_embed_editor_default_theme ?= 'github'
Range = require('ace/range').Range
$(document).ready () ->
  window.load_rails_embed_code_editor()


window.load_rails_embed_code_editor = () ->
  $('.rails_embed_code_editor').each () ->
    container = $(this)
    options = {
      theme: container.data('theme')
      mode: container.data('mode')
      filename: container.data('filename')
      first_line: container.data('first-line')
      last_line: container.data('last-line')
      editormode: container.data('editormode')
      highlight: compute_range(container.data('highlight'), container.data('first-line'))
    }
    setup_editor(container[0], options)


setup_editor = (element, options) ->
  defaults = {
    theme: window.rails_embed_editor_default_theme
    mode: 'ruby'
    firstLineNumber: 1
    editormode: 'readonly'
  }
  options = $.extend({}, defaults, options);
  editor = ace.edit(element)
  editor.commands.removeCommand('replace')
  editor.setTheme("ace/theme/" + options['theme']);
  editor.getSession().setMode("ace/mode/" + options['mode']);
  editor.setOption("firstLineNumber", options['first_line'])
  editor.setReadOnly(options['editormode'] != 'write')
  editor.setAutoScrollEditorIntoView();
  editor.setOption("maxLines", 40);
  editor.setOption("minLines", 5);
  editor.setHighlightActiveLine(false)

  editor.getSession().addMarker(options['highlight'], "editor_highlight", "text") unless options['highlight'] == null

  if options['editormode'] != 'readonly'
    options['last_line'] ?= options['firstLineNumber'] + editor.session.getLength()

    button = $('<div><button class="rails_embed_code_editor_button">Save</button></div>').appendTo(element).children()
    button.text('Enable edit') if options['editormode'] == 'readwrite'
    button.click () ->
      if options['editormode'] != 'readonly'
        if options['editormode'] == 'readwrite' and editor.getReadOnly()
          button.text('Save')
          editor.setReadOnly(false)
        else
          $.post('/rails_embed_editor/edit', {
            content: editor.getValue()
            first_line: options['first_line']<commit_msg>readdded highlight of active line but only when focused<commit_after>#
#= require_tree .
#= require ace/ace
#= require ace/mode-ruby
#= require ace/theme-monokai
#= require ace/theme-github

window.rails_embed_editor_default_theme ?= 'github'
Range = require('ace/range').Range
$(document).ready () ->
  window.load_rails_embed_code_editor()


window.load_rails_embed_code_editor = () ->
  $('.rails_embed_code_editor').each () ->
    container = $(this)
    options = {
      theme: container.data('theme')
      mode: container.data('mode')
      filename: container.data('filename')
      first_line: container.data('first-line')
      last_line: container.data('last-line')
      editormode: container.data('editormode')
      highlight: compute_range(container.data('highlight'), container.data('first-line'))
    }
    setup_editor(container[0], options)


setup_editor = (element, options) ->
  defaults = {
    theme: window.rails_embed_editor_default_theme
    mode: 'ruby'
    firstLineNumber: 1
    editormode: 'readonly'
  }
  options = $.extend({}, defaults, options);
  editor = ace.edit(element)
  editor.commands.removeCommand('replace')
  editor.setTheme("ace/theme/" + options['theme']);
  editor.getSession().setMode("ace/mode/" + options['mode']);
  editor.setOption("firstLineNumber", options['first_line'])
  editor.setReadOnly(options['editormode'] != 'write')
  editor.setAutoScrollEditorIntoView();
  editor.setOption("maxLines", 40);
  editor.setOption("minLines", 5);

  #highlight the current line only if its focus
  editor.setHighlightActiveLine(false)
  editor.on "focus", () ->
    editor.setHighlightActiveLine(true)
  editor.on "blur", () ->
    editor.setHighlightActiveLine(false)

  editor.getSession().addMarker(options['highlight'], "editor_highlight", "text") unless options['highlight'] == null

  if options['editormode'] != 'readonly'
    options['last_line'] ?= options['firstLineNumber'] + editor.session.getLength()

    button = $('<div><button class="rails_embed_code_editor_button">Save</button></div>').appendTo(element).children()
    button.text('Enable edit') if options['editormode'] == 'readwrite'
    button.click () ->
      if options['editormode'] != 'readonly'
        if options['editormode'] == 'readwrite' and editor.getReadOnly()
          button.text('Save')
          editor.setReadOnly(false)
        else
          $.post('/rails_embed_editor/edit', {
            content: editor.getValue()
            first_line: options['first_line']
{'fraction_non_alphanumeric': 0.1591051641229354, 'fraction_numerical': 0.0020907380305247754, 'mean_word_length': 4.36322869955157, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '979062', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1419, 'n_words': 237}