浏览代码

Let changes to the test file persist

Orta Therox 5 年之前
父节点
当前提交
53be7ba6a0
共有 1 个文件被更改,包括 21 次插入9 次删除
  1. 21 9
      test/index.html

+ 21 - 9
test/index.html

@@ -33,12 +33,9 @@
 <script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script>
 <script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script>
 
 
 <script>
 <script>
-	require([
-		'vs/basic-languages/monaco.contribution',
-		'vs/language/typescript/monaco.contribution'
-	], function() {
-		var editor = monaco.editor.create(document.getElementById('container'), {
-			value: [
+	let text = localStorage.getItem("code")
+	if (!text) {
+		text = [
 				'/* Game of Life',
 				'/* Game of Life',
 				' * Implemented in TypeScript',
 				' * Implemented in TypeScript',
 				' * To learn more about TypeScript, please visit http://www.typescriptlang.org/',
 				' * To learn more about TypeScript, please visit http://www.typescriptlang.org/',
@@ -164,11 +161,26 @@
 				'',
 				'',
 				'var game = new Conway.GameOfLife();',
 				'var game = new Conway.GameOfLife();',
 
 
-			].join('\n'),
-			language: 'typescript'
+			].join('\n')
+	}
+
+	require([
+		'vs/basic-languages/monaco.contribution',
+		'vs/language/typescript/monaco.contribution'
+	], function() {
+
+		var editor = monaco.editor.create(document.getElementById('container'), {
+			value: text,
+			language: 'typescript',
+			lightbulb: { enabled: true }
 		});
 		});
+
+		editor.onDidChangeModelContent(() => {
+			const code = editor.getModel().getValue()
+			localStorage.setItem("code", code)
+		})
 	});
 	});
 </script>
 </script>
 
 
 </body>
 </body>
-</html>
+</html>