Add refresh-preview action

This commit is contained in:
Junegunn Choi 2020-06-20 22:04:09 +09:00
parent a7aa08ce07
commit c33258832e
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 15 additions and 5 deletions

View File

@ -696,6 +696,7 @@ A key or an event can be bound to one or more of the following actions.
\fBpreview-page-up\fR \fBpreview-page-up\fR
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR) \fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
\fBprint-query\fR (print query and exit) \fBprint-query\fR (print query and exit)
\fBrefresh-preview\fR
\fBreload(...)\fR (see below for the details) \fBreload(...)\fR (see below for the details)
\fBreplace-query\fR (replace query string with the current selection) \fBreplace-query\fR (replace query string with the current selection)
\fBselect-all\fR (select all matches) \fBselect-all\fR (select all matches)

View File

@ -756,6 +756,8 @@ func parseKeymap(keymap map[int][]action, str string) {
appendAction(actAcceptNonEmpty) appendAction(actAcceptNonEmpty)
case "print-query": case "print-query":
appendAction(actPrintQuery) appendAction(actPrintQuery)
case "refresh-preview":
appendAction(actRefreshPreview)
case "replace-query": case "replace-query":
appendAction(actReplaceQuery) appendAction(actReplaceQuery)
case "backward-char": case "backward-char":

View File

@ -224,6 +224,7 @@ const (
actJump actJump
actJumpAccept actJumpAccept
actPrintQuery actPrintQuery
actRefreshPreview
actReplaceQuery actReplaceQuery
actToggleSort actToggleSort
actTogglePreview actTogglePreview
@ -1659,6 +1660,14 @@ func (t *Terminal) Loop() {
t.killPreview(code) t.killPreview(code)
} }
refreshPreview := func() {
if t.isPreviewEnabled() {
_, list := t.buildPlusList(t.preview.command, false)
t.cancelPreview()
t.previewBox.Set(reqPreviewEnqueue, list)
}
}
go func() { go func() {
var focusedIndex int32 = minItem.Index() var focusedIndex int32 = minItem.Index()
var version int64 = -1 var version int64 = -1
@ -1685,11 +1694,7 @@ func (t *Terminal) Loop() {
if focusedIndex != currentIndex || version != t.version { if focusedIndex != currentIndex || version != t.version {
version = t.version version = t.version
focusedIndex = currentIndex focusedIndex = currentIndex
if t.isPreviewEnabled() { refreshPreview()
_, list := t.buildPlusList(t.preview.command, false)
t.cancelPreview()
t.previewBox.Set(reqPreviewEnqueue, list)
}
} }
case reqJump: case reqJump:
if t.merger.Length() == 0 { if t.merger.Length() == 0 {
@ -1847,6 +1852,8 @@ func (t *Terminal) Loop() {
} }
case actPrintQuery: case actPrintQuery:
req(reqPrintQuery) req(reqPrintQuery)
case actRefreshPreview:
refreshPreview()
case actReplaceQuery: case actReplaceQuery:
if t.cy >= 0 && t.cy < t.merger.Length() { if t.cy >= 0 && t.cy < t.merger.Length() {
t.input = t.merger.Get(t.cy).item.text.ToRunes() t.input = t.merger.Get(t.cy).item.text.ToRunes()