Skip to content

Commit

Permalink
feat: preserve viz index after search
Browse files Browse the repository at this point in the history
  • Loading branch information
delanni committed Dec 16, 2023
1 parent efe8de3 commit a5d4c91
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion bundle.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -47128,6 +47128,24 @@
let downloadedSketches = [];
let localSketches = [];

const sGet = (key) => {
try {
const variableStr = localStorage.getItem("variables");
const variablesObj = JSON.parse(variablesStr);
return variablesObj[key];
} catch(e) {
return undefined;
}
}
const sPut = (key, value) => {
if (localStorage.getItem("variables") === null) {
localStorage.setItem("variables", '{}');
}
const o = JSON.parse(localStorage.getItem("variables"));
o[key]=value;
localStorage.setItem('variables', JSON.stringify(o));
}

window.xemitter = emitter;

emitter.on('DOMContentLoaded', function () {
Expand Down Expand Up @@ -47289,14 +47307,15 @@
repl.eval(editor.getValue())
})

let sketchIdx = 0;
let sketchIdx = sGet('sketchIdx') || 0;
// TODO: copy
emitter.on('gallery:nextSketch', (e) => {
if (e.altKey || e.shiftKey || e.backwards) {
sketchIdx--;
} else {
sketchIdx++;
}
sPut('sketchIdx', sketchIdx);

const editor = state.editor.editor;
clearAll()
Expand Down Expand Up @@ -47452,6 +47471,8 @@
editor.setValue(preamble + sketch.code);
}
repl.eval(editor.getValue());
sketchIdx = sketch.index || sketchIdx;
sPut('sketchIdx', sketchIdx);
document.title = sketch.name;
}

Expand Down

0 comments on commit a5d4c91

Please sign in to comment.