Skip to content

Commit

Permalink
feature: saving codebase on switching language
Browse files Browse the repository at this point in the history
  • Loading branch information
StealthX2k20 committed Aug 27, 2021
1 parent e3f03e7 commit 890215c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions hackIDE/static/hackIDE/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

$(document).ready(function(){

// to reset all the previous code base if present in local storage on reload
resetLocalStorage()
// contents of the editor at any step
var editorContent;
// language selected
Expand Down Expand Up @@ -40,6 +42,9 @@ $(document).ready(function(){
langBoilerplate['RUST'] = "fn main() {\n // The statements here will be executed when the compiled binary is called\n\n // Print text to the console\n println!(\"Hello World!\");\n}\n";
langBoilerplate['SCALA'] = "object Main extends App {\n // your code goes here\n}\n";

// changing boiler plate of languages according to the once present in local storage
updateBoilerPlate(langBoilerplate)

// flag to block requests when a request is running
var request_ongoing = false;

Expand Down Expand Up @@ -72,6 +77,14 @@ $(document).ready(function(){

checkForInitialData();

// function to auto-save current code in local storage
$("#editor").keyup(() => {
var editor = ace.edit("editor");
var languageCode = editor.getValue();
var lang = $("#lang").val();
localStorage.setItem(lang, languageCode);
})

function showResultBox() {
$(".output-response-box").show();
$(".run-status").show();
Expand Down Expand Up @@ -646,6 +659,8 @@ $(document).ready(function(){
// when lang is changed
$("#lang").change(function(){

updateBoilerPlate(langBoilerplate)

languageSelected = $("#lang").val();

// update the language (mode) for the editor
Expand Down Expand Up @@ -791,3 +806,21 @@ $(document).ready(function(){


});

// function to update the language boiler plates
function updateBoilerPlate(langBoilerplate)
{
var supportedLanguages = ['C', 'CPP', 'CSHARP', 'CSS', 'CLOJURE', 'HASKELL', 'JAVA', 'JAVASCRIPT', 'OBJECTIVEC', 'PERL', 'PHP', 'PYTHON', 'R', 'RUBY', 'RUST', 'SCALA'];

for(let i = 0; i < supportedLanguages.length; i++) {
let previousCode = localStorage.getItem(supportedLanguages[i]);
if(previousCode !== null && previousCode.length !== 0) {
langBoilerplate[supportedLanguages[i]] = previousCode;
}
}
}

// function to reset local storage
function resetLocalStorage() {
window.localStorage.clear();
}

0 comments on commit 890215c

Please sign in to comment.