<commit_before>var downloaded = []

$(document).on("page:change", function () {
    var editor = null

    function set_language(lang_id) {
	var code_editor_name = null

	// If the language has already been downloaded (along with it's JSON)
	if (lang_id < downloaded.length && downloaded[lang_id] != undefined) {
	    code_editor_name = downloaded[lang_id]
	    
	    if (editor != null) {
		editor.setOption("mode", code_editor_name)
	    }
	}
	else {
	    $.ajax("/admin/languages/" + lang_id + ".json").done(function (json_lang) {
		code_editor_name = json_lang["code_editor_name"]
		$("head").append($("<script src=\"/assets_static/codemirror/mode/" + code_editor_name + "/" + code_editor_name + ".js\"></script>"))
		downloaded[json_lang["id"]] = json_lang["code_editor_name"]

		if (editor != null) {
		    editor.setOption("mode", code_editor_name)
		}
	    })
	}
    }
    
    if ($("#snippet_select").length !== 0) {
	var editor = null
	
	function download_selected_snippet() {
	    $.ajax("/snippets/" + $("#snippet_select").val() + ".json").done(function (json_snip) {
		editor.getDoc().setValue(json_snip["contents"])
		set_language($("#snippet_select").val())
	    })
	}

	$("#snippet_select").change(download_selected_snippet)

	if ($(".CodeMirror").length === 0) {
	    editor = CodeMirror.fromTextArea($("#snippet")[0], {
		lineNumbers: false,
	    })
	}
	
	download_selected_snippet()
    }

    else if ($("#snippet_contents").length !== 0) {
	function load_selected_language() {
	    snippet_lang_id = $("#snippet_language_id").val()
	    // <script data-turbolinks-track="true" src="/assets/codemirror/modes/ruby.js?body=1"></script>
            set_language(snippet_lang_id)
	}

	$("#snippet_language_id").change(load_selected_language)

	load_selected_language()

	if ($(".CodeMirror").length === 0) {
	    editor = CodeMirror.fromTextArea($("#snippet_contents")[0], {
		lineNumbers: true,
	    })
	}
    }
})
<commit_msg>Fixed bug with select snippet<commit_after>var downloaded = []

$(document).on("page:change", function () {
    var editor = null

    function set_language(lang_id) {
	var code_editor_name = null

	// If the language has already been downloaded (along with it's JSON)
	if (lang_id < downloaded.length && downloaded[lang_id] != undefined) {
	    code_editor_name = downloaded[lang_id]
	    
	    if (editor != null) {
		editor.setOption("mode", code_editor_name)
	    }
	}
	else {
	    $.ajax("/admin/languages/" + lang_id + ".json").done(function (json_lang) {
		code_editor_name = json_lang["code_editor_name"]
		$("head").append($("<script src=\"/assets_static/codemirror/mode/" + code_editor_name + "/" + code_editor_name + ".js\"></script>"))
		downloaded[json_lang["id"]] = json_lang["code_editor_name"]

		if (editor != null) {
		    editor.setOption("mode", code_editor_name)
		}
	    })
	}
    }
    
    if ($("#snippet_select").length !== 0) {
	var editor = null
	
	function download_selected_snippet() {
	    $.ajax("/snippets/" + $("#snippet_select").val() + ".json").done(function (json_snip) {
		editor.getDoc().setValue(json_snip["contents"])
		set_language(json_snip['language_id'])
	    })
	}

	$("#snippet_select").change(download_selected_snippet)

	if ($(".CodeMirror").length === 0) {
	    editor = CodeMirror.fromTextArea($("#snippet")[0], {
		lineNumbers: false,
	    })
	}
	
	download_selected_snippet()
    }

    else if ($("#snippet_contents").length !== 0) {
	function load_selected_language() {
	    snippet_lang_id = $("#snippet_language_id").val()
	    // <script data-turbolinks-track="true" src="/assets/codemirror/modes/ruby.js?body=1"></script>
            set_language(snippet_lang_id)
	}

	$("#snippet_language_id").change(load_selected_language)

	load_selected_language()

	if ($(".CodeMirror").length === 0) {
	    editor = CodeMirror.fromTextArea($("#snippet_contents")[0], {
		lineNumbers: true,
	    })
	}
    }
})

{'fraction_non_alphanumeric': 0.17853483606557377, 'fraction_numerical': 0.003586065573770492, 'mean_word_length': 3.993606138107417, 'pattern_counts': {'":': 0, '<': 13, '<?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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3609192', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1303, 'n_words': 200}