From 1a9525c722040430f47a2a2343f3fe1d4fdfe1cc Mon Sep 17 00:00:00 2001 From: chriseth Date: Sun, 4 Oct 2015 10:58:05 +0200 Subject: [PATCH] Preserve previous contents. --- index.html | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 8eb433b0a5..748e616334 100644 --- a/index.html +++ b/index.html @@ -86,16 +86,27 @@ THE SOFTWARE. var SOL_CACHE_FILES_KEY = "sol-cache-files"; var editor = ace.edit("input"); - var session = editor.getSession(); - var Range = ace.require('ace/range').Range; + var session = editor.getSession(); + var Range = ace.require('ace/range').Range; var errMarkerId = null; var solFiles = JSON.parse( window.localStorage.getItem( SOL_CACHE_FILES_KEY ) ) || [SOL_CACHE_FILE]; if (solFiles.length === 0) solFiles = [SOL_CACHE_FILE]; - window.localStorage.setItem( SOL_CACHE_FILES_KEY, JSON.stringify( solFiles ) ); - var solCache = window.localStorage.getItem( SOL_CACHE_FILE ) || BALLOT_EXAMPLE; window.localStorage.setItem( SOL_CACHE_FILE, solCache ) + + if (window.localStorage.getItem('sol-cache')) { + // Backwards-compatibility + var count = ''; + while (window.localStorage.getItem('Untitled' + count)) + count = (count - 0) + 1; + window.localStorage.setItem('Untitled' + count, window.localStorage.getItem('sol-cache')); + window.localStorage.removeItem('sol-cache'); + solFiles.push('Untitled' + count); + } + + window.localStorage.setItem( SOL_CACHE_FILES_KEY, JSON.stringify( solFiles ) ); + editor.setValue( solCache, 1 );