Prevent index out of range error

Fix #2293
This commit is contained in:
Junegunn Choi 2020-12-23 10:27:57 +09:00
parent ab3937ee5a
commit f37ccaa64f
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -2130,7 +2130,8 @@ func (t *Terminal) Loop() {
} }
} }
toggle := func() bool { toggle := func() bool {
if t.cy < t.merger.Length() && t.toggleItem(t.merger.Get(t.cy).item) { current := t.currentItem()
if current != nil && t.toggleItem(current) {
req(reqInfo) req(reqInfo)
return true return true
} }
@ -2241,8 +2242,9 @@ func (t *Terminal) Loop() {
case actRefreshPreview: case actRefreshPreview:
refreshPreview(t.previewOpts.command) refreshPreview(t.previewOpts.command)
case actReplaceQuery: case actReplaceQuery:
if t.cy >= 0 && t.cy < t.merger.Length() { current := t.currentItem()
t.input = t.merger.Get(t.cy).item.text.ToRunes() if current != nil {
t.input = current.text.ToRunes()
t.cx = len(t.input) t.cx = len(t.input)
} }
case actAbort: case actAbort: