Reordered prompt done callback to avoid accessing out of bound history (#3318)

* Reordered prompt done callback to avoid accessing out of bound history

* Formatting
This commit is contained in:
Neko Box Coder 2024-06-02 19:00:13 +01:00 committed by GitHub
parent e9bd1b35f4
commit dd913df9e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -143,13 +143,12 @@ func (i *InfoBuf) DonePrompt(canceled bool) {
if i.PromptCallback != nil {
if canceled {
i.Replace(i.Start(), i.End(), "")
i.PromptCallback("", true)
h := i.History[i.PromptType]
i.History[i.PromptType] = h[:len(h)-1]
i.PromptCallback("", true)
} else {
resp := string(i.LineBytes(0))
i.Replace(i.Start(), i.End(), "")
i.PromptCallback(resp, false)
h := i.History[i.PromptType]
h[len(h)-1] = resp
@ -160,6 +159,8 @@ func (i *InfoBuf) DonePrompt(canceled bool) {
break
}
}
i.PromptCallback(resp, false)
}
// i.PromptCallback = nil
}