mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Add undo/redo history
This commit is contained in:
@@ -157,7 +157,7 @@
|
||||
<textarea type="text" class="form-control code" onchange="updateField(this)" onfocus="this.select()" style="height: 0px"></textarea>
|
||||
</div>
|
||||
<div class="input-group mt-3" data-type="json-list">
|
||||
<textarea class="form-control code" onchange="updateJsonListField(this)" rows=3></textarea>
|
||||
<textarea class="form-control code" onchange="updateField(this)" rows=3></textarea>
|
||||
</div>
|
||||
<div class="input-group mt-3" data-type="nbt">
|
||||
<div class="input-group-prepend">
|
||||
|
||||
44
model.js
44
model.js
@@ -20,6 +20,9 @@ let table = {
|
||||
}
|
||||
]
|
||||
};
|
||||
let historyBuffer = 100;
|
||||
let history = [];
|
||||
let historyIndex = -1;
|
||||
invalidated();
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
@@ -34,6 +37,47 @@ if (params.has('q')) {
|
||||
$('.container').removeClass('d-none');
|
||||
}
|
||||
|
||||
$(document).keydown(function(e){
|
||||
if (e.which === 89 && e.ctrlKey ){
|
||||
redo();
|
||||
} else if (e.which === 90 && e.ctrlKey ){
|
||||
undo();
|
||||
}
|
||||
});
|
||||
|
||||
function undo() {
|
||||
if (historyIndex > 0) {
|
||||
historyIndex -= 1;
|
||||
table = JSON.parse(history[historyIndex]);
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
function redo() {
|
||||
if (historyIndex < history.length - 1) {
|
||||
historyIndex += 1;
|
||||
table = JSON.parse(history[historyIndex]);
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
function invalidated() {
|
||||
if (historyIndex === history.length - 1) {
|
||||
historyIndex += 1;
|
||||
history.push(JSON.stringify(table));
|
||||
} else {
|
||||
historyIndex += 1;
|
||||
history = history.slice(0, historyIndex);
|
||||
history.push(JSON.stringify(table));
|
||||
}
|
||||
if (history.length > historyBuffer) {
|
||||
console.log('remove history');
|
||||
historyIndex -= 1;
|
||||
history.splice(0, 1);
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
|
||||
function updateTableType() {
|
||||
table.type = $('#tableType').val();
|
||||
invalidated();
|
||||
|
||||
4
view.js
4
view.js
@@ -7,11 +7,11 @@ function changeVersion(version) {
|
||||
$('#versionLabel').text(version);
|
||||
structure = json.root;
|
||||
components = json.components;
|
||||
invalidated();
|
||||
updateView();
|
||||
});
|
||||
}
|
||||
|
||||
function invalidated() {
|
||||
function updateView() {
|
||||
if (structure) {
|
||||
generateTable();
|
||||
if (i18next.isInitialized) {
|
||||
|
||||
Reference in New Issue
Block a user