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.
Problem:
When I edit text, I do it in a
sequenceof multipleactions, 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 anddebounce_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,DeferSaveandCancelDeferedSaveDeferSaveevent (TextChanged,InsertLeave, ...) happens, start a timert, which will save the file if it finishesCancelDeferedSaveevent (InsertEnter,TextChanged, enter, ...) happens, cancel all not yet called timersImmediateSaveevents (BufferLeave, VimClose, ...) happen, save immediatelyThis makes it so, that
actionsthat 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.