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

Save only after sequence of actions finished, not after each action #72

Open
primeapple opened this issue Feb 7, 2023 · 1 comment
Open

Comments

@primeapple
Copy link

Problem:

When I edit text, I do it in a sequence of multiple actions, that I execute rapidly after each other.
For example, I delete a word (daw), change a word (caw, after that typing and exiting insert mode), insert the deleted word two lines below.
With the current implementation that would save up to 4 times (TextChanged, TextChanged, InsertLeave, TextChanged), depending on my typing speed and debounce_delay.
This triggers any external service like Webpack up to 4 times, once per action.

I want it to be only triggered 1 time, once per sequence.

Idea:

Add 3 types of events: ImmediateSave, DeferSave and CancelDeferedSave

  • when DeferSave event (TextChanged, InsertLeave, ...) happens, start a timer t, which will save the file if it finishes
  • when CancelDeferedSave event (InsertEnter, TextChanged, enter, ...) happens, cancel all not yet called timers
  • when ImmediateSave events (BufferLeave, VimClose, ...) happen, save immediately

This makes it so, that actions that occur fast after another will cancel each other out and only the last action gets saved.
The Timer would have to be something like 2 seconds.

Sometimes however we need to save immediately, for example when closing/leaving a buffer or closing nvim.
So we need another set of events called ImmediateSave.

@okuuva
Copy link

okuuva commented Feb 12, 2023

Related to #61. I'd be happy with just a plain "dumb" delay for starters but this sounds like a much better solution to the problem.

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

No branches or pull requests

2 participants