From dd913df9e9b92bebeac26b22068cc30ffe1f8804 Mon Sep 17 00:00:00 2001 From: Neko Box Coder <93885501+Neko-Box-Coder@users.noreply.github.com> Date: Sun, 2 Jun 2024 19:00:13 +0100 Subject: [PATCH] Reordered prompt done callback to avoid accessing out of bound history (#3318) * Reordered prompt done callback to avoid accessing out of bound history * Formatting --- internal/info/infobuffer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/info/infobuffer.go b/internal/info/infobuffer.go index 2dbccbca..eaeadbe0 100644 --- a/internal/info/infobuffer.go +++ b/internal/info/infobuffer.go @@ -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 }