Reordered prompt done callback to avoid accessing out of bound history #3318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to https://pkg.go.dev/github.com/zyedidia/micro/[email protected]/internal/info#InfoBuf.Prompt
A lua script can provide a done callback when the prompt has finished (enter is pressed).
This works fine until the done callback itself wants to have another prompt, for example multiple questions to configure an action.
The behavior in main right now will crash with
So if I have something like this
It won't work and crash inside the 2nd prompt.
This is due to the 2nd call in the prompt trying to access history while the first prompt has not finished modifying the history.
See
micro/internal/info/infobuffer.go
Lines 97 to 109 in e9bd1b3
and
micro/internal/info/infobuffer.go
Lines 150 to 154 in e9bd1b3
where line 152 is calling the done callback and we are still modifying the history for the current prompt on line 153+
The proposed solution just needs to reorder the done callback to the end of the block where we have finished modifying the history so that the next prompt call can safely modify it.