jmacdonald / amp

A complete text editor for your terminal.
https://amp.rs
Other
3.67k stars 105 forks source link

Persistent modes #281

Open jmacdonald opened 4 months ago

jmacdonald commented 4 months ago

As of today, Amp tracks its current/active mode using a single enum field on the Application type. When the active mode is changed, the old mode is discarded and a new one is constructed. A side effect of this is that the active mode's state is lost during the transition. There are situations where persisting and recalling state across modes is beneficial:

The first two behaviors above exist today, but as you'll see in the diff below, they're implemented by explicitly storing required state in their relevant modes or the Application type itself. This has helped minimize and isolate the complexity involved with persistent state, but as we look to implement more features that require it, the pattern justifies building a generalized system that handles this for all use cases.

That generalized system is the focus of this PR. As you'll see below, we now build all application modes up front, store them in a hash map, and recall them when switching modes. To do so, I needed to introduce the following notable changes:

Once this lands, we'll be able to leverage these persistent modes to build some neat features that should really help improve the ergonomics of Amp. 😎