Skip to content

Commit 0adab0c

Browse files
authored
Theme persist verilog editor (CircuitVerse#3006)
* feature: verilog-themes CircuitVerse#2829 * feature: apply theme change on selecting from dropdown CircuitVerse#2829 * removed some themes for verilog editor * restoring previous theme of code editor on reload or revisit * fix: some possible code climate issues * fixed code-climate issue convert let to const
1 parent 7a45d04 commit 0adab0c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

app/views/simulator/edit.html.erb

+7-7
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,15 @@
306306
<p class="text-center mb-2">Select a theme: </p>
307307
<select id="selectVerilogTheme" class="applyTheme" style="width:90%;">
308308
<optgroup label="Light Themes">
309-
<option value="1">default</option>
310-
<option value="2">solarized</option>
311-
<option value="3">elegant</option>
312-
<option value="4">neat</option>
313-
<option value="5">idea</option>
314-
<option value="6">neo</option>
309+
<option>default</option>
310+
<option>solarized</option>
311+
<option>elegant</option>
312+
<option>neat</option>
313+
<option>idea</option>
314+
<option>neo</option>
315315
</optgroup>
316316
<optgroup label="Dark Themes">
317-
<option value="7">blackboard</option>
317+
<option>blackboard</option>
318318
<option>cobalt</option>
319319
<option>night</option>
320320
<option>the-matrix</option>

simulator/src/Verilog2CV.js

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function saveVerilogCode() {
4545
export function applyVerilogTheme() {
4646
var dropdown = document.getElementById('selectVerilogTheme');
4747
var theme = dropdown.options[dropdown.selectedIndex].innerHTML;
48+
localStorage.setItem('verilog-theme', theme);
4849
editor.setOption('theme', theme);
4950
}
5051

@@ -216,6 +217,13 @@ export function setupCodeMirrorEnvironment() {
216217
extraKeys: {"Ctrl-Space": "autocomplete"}
217218
});
218219

220+
if (!localStorage.getItem('verilog-theme')) {
221+
localStorage.setItem('verilog-theme', 'default');
222+
} else {
223+
const prevtheme = localStorage.getItem('verilog-theme');
224+
editor.setOption('theme', prevtheme);
225+
}
226+
219227
editor.setValue("// Write Some Verilog Code Here!")
220228
setTimeout(function() {
221229
editor.refresh();

0 commit comments

Comments
 (0)