Revert
This commit is contained in:
parent
b78362243a
commit
8067b9bb46
14
src/main.js
14
src/main.js
|
|
@ -48,6 +48,7 @@ let maxSmoothAngle = 0.6;
|
||||||
|
|
||||||
let undoStack = [];
|
let undoStack = [];
|
||||||
let redoStack = [];
|
let redoStack = [];
|
||||||
|
let lastSaveIndex = 0;
|
||||||
|
|
||||||
let layoutElements = []
|
let layoutElements = []
|
||||||
|
|
||||||
|
|
@ -2177,6 +2178,7 @@ async function _save(path) {
|
||||||
const contents = JSON.stringify(fileData);
|
const contents = JSON.stringify(fileData);
|
||||||
await writeTextFile(path, contents)
|
await writeTextFile(path, contents)
|
||||||
filePath = path
|
filePath = path
|
||||||
|
lastSaveIndex = undoStack.length - 1;
|
||||||
console.log(`${path} saved successfully!`);
|
console.log(`${path} saved successfully!`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error saving text file:", error);
|
console.error("Error saving text file:", error);
|
||||||
|
|
@ -2240,6 +2242,7 @@ async function open() {
|
||||||
await actions[action.name].execute(action.action)
|
await actions[action.name].execute(action.action)
|
||||||
undoStack.push(action)
|
undoStack.push(action)
|
||||||
}
|
}
|
||||||
|
lastSaveIndex = undoStack.length - 1;
|
||||||
updateUI()
|
updateUI()
|
||||||
} else {
|
} else {
|
||||||
await messageDialog(`File ${path} was created in a newer version of Lightningbeam and cannot be opened in this version.`, { title: 'File version mismatch', kind: 'error' });
|
await messageDialog(`File ${path} was created in a newer version of Lightningbeam and cannot be opened in this version.`, { title: 'File version mismatch', kind: 'error' });
|
||||||
|
|
@ -2258,6 +2261,12 @@ async function open() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function revert() {
|
||||||
|
for (let _=0; undoStack.length > lastSaveIndex+1; _++) {
|
||||||
|
undo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function importImage() {
|
async function importImage() {
|
||||||
const path = await openFileDialog({
|
const path = await openFileDialog({
|
||||||
multiple: false,
|
multiple: false,
|
||||||
|
|
@ -3428,6 +3437,11 @@ async function updateMenu() {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
action: open,
|
action: open,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: 'Revert',
|
||||||
|
enabled: undoStack.length > lastSaveIndex,
|
||||||
|
action: revert,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: 'Import Image...',
|
text: 'Import Image...',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue