<commit_before>$(document).ready(() => {

  updateTextInPreview();
  addNewFile();
  saveFile();
	readSelectedFile();

});

function updateTextInPreview() {
  $('textarea.form-control').keyup(function () {
    $('.preview-content')[0].innerHTML = marked(this.value);
  });
}

function addNewFile() {
	let table = $('.table');
	let textarea = $('textarea.form-control')[0];
	let previewPanel = $('.preview-content');
	let currentFileName = $('.filename')

  $('.new-file').on('click', function () {
		previewPanel.text('');
		textarea.value = '';

		table.find('tr:last').before('<tr><td>untitled.md<span><i class="fa fa-trash" aria-hidden="true"></i></span></td></tr>');
  	currentFileName.html('untitled.md');

		// Delay prompt for new file name to allow the added row to update with 'untitled.md' first
		let newFileName = new Promise((resolve) => {
			setTimeout( () => {
				let fileStr = prompt('Name your markdown file');
				if(fileStr === '') { fileStr = 'untitled.md'; }
				resolve(fileStr);
				}, 300);
			});

		// Add chosen filename to new row element
    newFileName.then((result) => {
      let str = '<tr><td>' + result + '<span><i class="fa fa-trash" aria-hidden="true"></i></span></td></tr>';
      table.find('tr:last').prev().replaceWith(str);
      currentFileName.text(result);
    });
  });
}

function saveFile() {
  $('.save').click(function () {

		let data = {
			data: $('textarea.form-control')[0].value,
			file: $('.filename')[0].textContent
		};

		fetch('/newfile', {
			method: 'post',
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			body: JSON.stringify(data)
		})
		.then(function(response) {
			readSelectedFile();
		})
		.catch(function(e) {
			console.log('There was an error ' + e);
		})
	});
}

function readSelectedFile() {
	$('tr').click(function () {
    console.log('you clicked me')
		let text = (this.innerText).toLowerCase();
		let params = /^.*(?=(\.md))/.exec(text)[0];
		let url = '/' + params;

		fetch(url).then(function(response) {
			return response.text();
		}).then(function(content) {
			$('textarea.form-control').text(content);
			$('.preview-content').html(marked(content));
      $('.filename').text(text);
		});
	});
}
<commit_msg>Repair bug which was preventing repopulate after new file creation<commit_after>$(document).ready(() => {

  updateTextInPreview();
  addNewFile();
  saveFile();
	readSelectedFile();

});

function updateTextInPreview() {
  $('textarea.form-control').keyup(function () {
    $('.preview-content')[0].innerHTML = marked(this.value);
  });
}

function addNewFile() {
	let table = $('.table');
	let textarea = $('textarea.form-control')[0];
	let previewPanel = $('.preview-content');
	let currentFileName = $('.filename')

  $('.new-file').on('click', function () {
		previewPanel.text('');
		textarea.value = '';

		table.find('tr:last').before('<tr><td>untitled.md<span><i class="fa fa-trash" aria-hidden="true"></i></span></td></tr>');
  	currentFileName.html('untitled.md');

		// Delay prompt for new file name to allow the added row to update with 'untitled.md' first
		let newFileName = new Promise((resolve) => {
			setTimeout( () => {
				let fileStr = prompt('Name your markdown file');
				if(fileStr === '') { fileStr = 'untitled.md'; }
				resolve(fileStr);
				}, 300);
			});

		// Add chosen filename to new row element
    newFileName.then((result) => {
      let str = '<tr><td>' + result + '<span><i class="fa fa-trash" aria-hidden="true"></i></span></td></tr>';
      table.find('tr:last').prev().replaceWith(str);
      currentFileName.text(result);
    });
  });
}

function saveFile() {
  $('.save').click(function () {
		let data = {
			data: $('textarea.form-control')[0].value,
			file: $('.filename')[0].textContent
		};

		fetch('/newfile', {
			method: 'post',
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			body: JSON.stringify(data)
		})
		.then(() => {
      readSelectedFile();
    })
		.catch(function(e) {
			console.log('There was an error ' + e);
		})
	});
}

function readSelectedFile() {
	$('tr').click(function () {
		let text = (this.innerText).toLowerCase();
		let params = /^.*(?=(\.md))/.exec(text)[0];
		let url = '/' + params;

		fetch(url).then(function(response) {
			return response.text();
		}).then(function(content) {
      readSelectedFile()
			$('textarea.form-control')[0].value = content;
			$('.preview-content').html(marked(content));
      $('.filename').text(text);
		});
	});
}

{'fraction_non_alphanumeric': 0.22251655629139072, 'fraction_numerical': 0.0037527593818984547, 'mean_word_length': 3.7197916666666666, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 44, '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': '719531', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1480, 'n_words': 272}