<commit_before>import _ from 'underscore';
import $ from 'jquery';
import mermaid from 'mermaid';
import 'mermaid/dist/mermaid.forest.css!';

const remote = require('electron').remote;

/////////////////////////////////////
// for debugging                   //
/////////////////////////////////////
window.remote = remote;


console.log('app version is', remote.app.getVersion());
console.log('main.js underscore version is', _.VERSION);
console.log('main.js jquery     version is', $.fn.jquery);
console.log('main.js mermaid    version is', mermaid.version());

mermaidAPI.initialize({startOnLoad:false});

$(function(){
  let diagram = [
    'graph',
    'sequenceDiagram',
    'gantt'
  ];
  let filePath;

  window.$lbEditor = $('#lb-editor');
  window.$lbCanvas = $('#lb-canvas');

  $lbCanvas.render = function(){
    $lbCanvas.empty();
    mermaidAPI.render('lb-output', $lbEditor.val(), function(svgCode, bindFunctions){
      $lbCanvas.html(svgCode);
    });
  };

  $lbCanvas.render();

  $(document.body).on('keypress', (e) => {
    if (e.ctrlKey && e.keyCode === 19) {
      if (!filePath) {
        remote.dialog.showSaveDialog({
          title: 'select file...'
        }, function(res){
          console.log('showOpenDialog', res);
        });
      }

      console.log('render');
      // TODO change command pattern
      $lbCanvas.render();
    }
  });
});<commit_msg>Ctrl + S -> save file<commit_after>import _ from 'underscore';
import $ from 'jquery';
import mermaid from 'mermaid';
import 'mermaid/dist/mermaid.forest.css!';

const remote = require('electron').remote;
const fs     = require('fs');

/////////////////////////////////////
// for debugging                   //
/////////////////////////////////////
window.remote = remote;


console.log('app version is', remote.app.getVersion());
console.log('main.js underscore version is', _.VERSION);
console.log('main.js jquery     version is', $.fn.jquery);
console.log('main.js mermaid    version is', mermaid.version());

mermaidAPI.initialize({startOnLoad:false});

$(function(){
  let diagram = [
    'graph',
    'sequenceDiagram',
    'gantt'
  ];
  let filePath;

  window.$lbEditor = $('#lb-editor');
  window.$lbCanvas = $('#lb-canvas');

  $lbCanvas.render = function(){
    $lbCanvas.empty();
    mermaidAPI.render('lb-output', $lbEditor.val(), function(svgCode, bindFunctions){
      $lbCanvas.html(svgCode);
    });
  };

  $lbCanvas.render();

  $(document.body).on('keypress', (e) => {
    if (e.ctrlKey && e.keyCode === 19) {
      if (filePath) {
        fs.writeFile(filePath, $lbEditor.val(), (err) => {
          if (err) throw err;
          console.log('It\'s saved!');
        });
      } else {
        remote.dialog.showSaveDialog({
          title: 'save file...'
        }, function(selectedFilePath){
          console.log('showSaveDialog', selectedFilePath);
          fs.writeFile(selectedFilePath, $lbEditor.val(), (err) => {
            if (err) throw err;

            console.log('It\'s saved!');
            window.document.title = selectedFilePath;
            filePath = selectedFilePath;
          });
        });
      }

      console.log('render');
      // TODO change command pattern
      $lbCanvas.render();
    }
  });
});
{'fraction_non_alphanumeric': 0.21490147783251232, 'fraction_numerical': 0.0012315270935960591, 'mean_word_length': 2.3529411764705883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '190170', 'n_tokens_mistral': 992, 'n_tokens_neox': 964, 'n_words': 191}