diff --git a/js/ui/history.js b/js/ui/history.js index 2a2018b..9af8303 100644 --- a/js/ui/history.js +++ b/js/ui/history.js @@ -25,18 +25,26 @@ }; _commands_events.on((message) => { + if (message.action === "run") { + Array.from(historyView.children).forEach((child) => { + if ( + !commands.history.find((entry) => `hist-${entry.id}` === child.id) + ) { + console.log("Removing " + entry.id); + historyView.removeChild(child); + } + }); + } + commands.history.forEach((entry, index) => { - console.log("Inserting " + entry.id); if (!document.getElementById(`hist-${entry.id}`)) { + console.log("Inserting " + 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"]);