Skip to content

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

@primeapple

Description

@primeapple

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions