<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp" -->

---
title: Reusable Undo System - Tsoding | daily.dev
description: A live-coding stream walks through designing and implementing a reusable undo/redo history system for a custom music player written in the Jai programming...
canonical: https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Reusable Undo System - Tsoding | daily.dev
og:description: A live-coding stream walks through designing and implementing a reusable undo/redo history system for a custom music player written in the Jai programming...
og:url: https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp
og:image: https://api.daily.dev/og/posts/UY8SG7AkP.png
og:image:alt: Reusable Undo System - Tsoding
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Reusable Undo System - Tsoding

**[Tsoding Daily](https://daily.dev/sources/tsoding_daily)** · 129 min read · 0 upvotes · 0 comments

## Summary

A live-coding stream walks through designing and implementing a reusable undo/redo history system for a custom music player written in the Jai programming language. The streamer reasons through data structure choices (a dynamic array with a cursor), edge cases around branching history when a new action follows an undo, and how to avoid spamming history on repeated or invalid songs. After debugging cursor-off-by-one bugs and empty-history edge cases, the working undo/redo is wired to Ctrl+Z and Ctrl+Shift+Z, and the session ends by exploring generalizing the same history data structure (using Jai generics/templates) to also support undo for a custom text edit field.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=YTe-cpDgyKs>

## Questions this post answers

### How do you implement a simple undo/redo system using a dynamic array instead of a tree?

Use a dynamic array of history entries with an integer cursor pointing at the current entry. Undo decrements the cursor and returns the entry at that index; redo increments it. When a new entry is added while the cursor isn't at the end, truncate the array to the cursor position first, discarding the abandoned branch, before appending the new entry. This avoids the complexity of Emacs-style tree-based undo history.

_Developers weighing undo history designs can find implementation walkthroughs like this on daily.dev._

### Why does most undo/redo functionality discard the redo branch when you make a new change after undoing?

Most editors and software simply forget the abandoned branch for simplicity rather than preserving it as a navigable tree, unlike Git's branching model. Emacs is a notable exception, traversing its undo history as a tree in roughly depth-first order, but this adds significant complexity for what is often a simple task like skipping back to a previous action.

_Anyone comparing undo history strategies across editors can track these design tradeoffs on daily.dev._

## Similar posts on daily.dev

- [Undo, Redo, and the Command Pattern](https://daily.dev/posts/undo-redo-and-the-command-pattern-lqvrqvwp4) · Lobsters · 0 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#data-structures](https://daily.dev/tags/data-structures)

[View this post on daily.dev](https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Reusable Undo System - Tsoding","url":"https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp"},"datePublished":"2026-09-15T15:50:32.561Z","dateModified":"2026-09-15T15:56:00.280Z","description":"A live-coding stream walks through designing and implementing a reusable undo/redo history system for a custom music player written in the Jai programming...","image":"https://i.ytimg.com/vi/YTe-cpDgyKs/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/YTe-cpDgyKs/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Tsoding Daily","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Tsoding Daily","logo":"https://media.daily.dev/image/upload/s--6msWm9pp--/f_auto/v1728806157/logos/tsoding_daily","url":"https://daily.dev/sources/tsoding_daily"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,data-structures","timeRequired":"PT129M","video":{"@type":"VideoObject","name":"Reusable Undo System - Tsoding","description":"A live-coding stream walks through designing and implementing a reusable undo/redo history system for a custom music player written in the Jai programming...","thumbnailUrl":"https://i.ytimg.com/vi/YTe-cpDgyKs/sddefault.jpg","uploadDate":"2026-09-15T15:50:32.561Z","duration":"PT129M","url":"https://api.daily.dev/r/UY8SG7AkP","embedUrl":"https://www.youtube.com/embed/YTe-cpDgyKs"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Tsoding Daily","item":"https://daily.dev/sources/tsoding_daily"},{"@type":"ListItem","position":3,"name":"Reusable Undo System - Tsoding"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/reusable-undo-system---tsoding-uy8sg7akp#faq","mainEntity":[{"@type":"Question","name":"How do you implement a simple undo/redo system using a dynamic array instead of a tree?","acceptedAnswer":{"@type":"Answer","text":"Use a dynamic array of history entries with an integer cursor pointing at the current entry. Undo decrements the cursor and returns the entry at that index; redo increments it. When a new entry is added while the cursor isn't at the end, truncate the array to the cursor position first, discarding the abandoned branch, before appending the new entry. This avoids the complexity of Emacs-style tree-based undo history. Developers weighing undo history designs can find implementation walkthroughs like this on daily.dev."}},{"@type":"Question","name":"Why does most undo/redo functionality discard the redo branch when you make a new change after undoing?","acceptedAnswer":{"@type":"Answer","text":"Most editors and software simply forget the abandoned branch for simplicity rather than preserving it as a navigable tree, unlike Git's branching model. Emacs is a notable exception, traversing its undo history as a tree in roughly depth-first order, but this adds significant complexity for what is often a simple task like skipping back to a previous action. Anyone comparing undo history strategies across editors can track these design tradeoffs on daily.dev."}}]}
```

