Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent modes #281

Merged
merged 37 commits into from
Sep 21, 2024
Merged

Persistent modes #281

merged 37 commits into from
Sep 21, 2024

Conversation

jmacdonald
Copy link
Owner

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:

  • when searching/replacing text, preserving the search query so you can quickly find the next match after making edits
  • when selecting a range of text in Select/SelectLine modes, temporarily switching to jump mode to select the end of the range
  • pinning search tokens in open mode to narrow down results to your area of focus when working in larger projects

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:

  • build all modes when initializing the Application type to hydrate the map
  • add a new ModeKey type as a stateless enum key into the map
  • add a reset method to modes where a clean slate is expected (e.g. rebuilding open mode's project directory index)

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. 😎

@jmacdonald jmacdonald self-assigned this Apr 5, 2024
@jmacdonald jmacdonald force-pushed the persistent-modes branch 5 times, most recently from 48bab5e to 2335e6b Compare April 8, 2024 03:45
@jmacdonald jmacdonald force-pushed the persistent-modes branch 7 times, most recently from b4e6cfa to bf711cf Compare September 10, 2024 02:58
@jmacdonald jmacdonald force-pushed the persistent-modes branch 3 times, most recently from c2db512 to 0d82d9a Compare September 21, 2024 17:05
@jmacdonald jmacdonald merged commit 1c756d9 into main Sep 21, 2024
1 check passed
@jmacdonald jmacdonald deleted the persistent-modes branch September 21, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant