openOutpaint/js/ui/history.js
Victor Seiji Hariki 250c833895 Added tool menu and migrated image generation ot new input
Also updates a lot of other things (brush size now independent from
scale factor, split some files, and a lot other things; removed erase
safeguard as now erase is supported by undo/redo; tried adding github
prettier autoformatting to pull requests;

may have some other things as well

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>

Former-commit-id: 0ba21f23c69f9dca2c3189a838b945900b01f81d
2022-11-22 19:28:27 -03:00

60 lines
1.7 KiB
JavaScript

(() => {
const historyView = document.getElementById("history");
const makeHistoryEntry = (index, id, title) => {
const historyItemTitle = document.createElement("span");
historyItemTitle.classList.add(["title"]);
historyItemTitle.textContent = `${index} - ${title}`;
const historyItem = document.createElement("div");
historyItem.id = id;
historyItem.classList.add(["history-item"]);
historyItem.title = id;
historyItem.onclick = () => {
const diff = commands.current - index;
if (diff < 0) {
commands.redo(Math.abs(diff));
} else {
commands.undo(diff);
}
};
historyItem.appendChild(historyItemTitle);
return historyItem;
};
_commands_events.on((message) => {
commands.history.forEach((entry, index) => {
console.log("Inserting " + entry.id);
if (!document.getElementById(`hist-${entry.id}`)) {
historyView.appendChild(
makeHistoryEntry(index, `hist-${entry.id}`, entry.title)
);
}
});
while (historyView.children.length > commands.history.length)
historyView.removeChild(historyView.lastElementChild);
Array.from(historyView.children).forEach((child, index) => {
if (index === commands.current) {
child.classList.remove(["past"]);
child.classList.add(["current"]);
child.classList.remove(["future"]);
} else if (index < commands.current) {
child.classList.add(["past"]);
child.classList.remove(["current"]);
child.classList.remove(["future"]);
} else {
child.classList.remove(["past"]);
child.classList.remove(["current"]);
child.classList.add(["future"]);
}
});
if (message.action === "run") {
historyView.scrollTo(0, historyView.scrollHeight);
}
});
})();