Skip to content
Myr

'reload' action should be allowed even where there's no match

Before adoption: this commit came in with the history the project adopted, so no landing records it.

If the command template doesn't have any placeholder expressions. : | fzf --bind 'space:reload:seq 10'

authored by Junegunn Choi · committed by Junegunn Choi · parent 5e42b1c · Browse files · 2 files+16 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−7 removed

  • tests:+7 added−0 removed
  • other:+9 added−7 removed

2 files+16 added−7 removed

modified:src/terminal.go+9 added-7 removed
1235 unmodified lines
12361237 return false, matchWithoutFlags, flags1238}12391240func hasPreviewFlags(template string) (plus bool, query bool) {1240func hasPreviewFlags(template string) (slot bool, plus bool, query bool) {1241 for _, match := range placeholder.FindAllString(template, -1) {1242 _, _, flags := parsePlaceholder(match)1243 if flags.plus {1244 plus = true1245 }1246 if flags.query {1247 query = true1248 }1249 slot = true1250 }1251 return1252}1253
155 unmodified lines
1409}14101411func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) {1412 current := t.currentItem()1412 plus, query := hasPreviewFlags(template)1413 _, plus, query := hasPreviewFlags(template)1414 if !(query && len(t.input) > 0 || (forcePlus || plus) && len(t.selected) > 0) {1415 return current != nil, []*Item{current, current}1416 }1417
627 unmodified lines
2045 case actReload:2046 t.failed = nil20472048 valid, list := t.buildPlusList(a.a, false)2048 // If the command template has {q}, we run the command even when the2049 // query string is empty.2049 if !valid {2050 // We run the command even when there's no match2051 // 1. If the template doesn't have any slots2052 // 2. If the template has {q}2051 _, query := hasPreviewFlags(a.a)2052 valid = query2053 slot, _, query := hasPreviewFlags(a.a)2054 valid = !slot || query2055 }2056 if valid {2057 command := replacePlaceholder(a.a,2058 t.ansi, t.delimiter, t.printsep, false, string(t.input), list)
37 unmodified lines
2096 }20972098 if queryChanged {2099 if t.isPreviewEnabled() {2098 _, q := hasPreviewFlags(t.preview.command)2100 _, _, q := hasPreviewFlags(t.preview.command)2101 if q {2102 t.version++2103 }2104 }
64 unmodified lines
modified:test/test_go.rb+7 added
1638 unmodified lines
1639 tmux.send_keys '555'1640 tmux.until { |lines| lines.item_count == 553 && lines.match_count == 1 }1641 tmux.until { |lines| !lines[-2].include?('(1/2)') }1642 end16431644 def test_reload_even_when_theres_no_match1645 tmux.send_keys %(: | #{FZF} --bind 'space:reload(seq 10)'), :Enter1646 tmux.until { |lines| lines.item_count.zero? }1647 tmux.send_keys :Space1648 tmux.until { |lines| lines.item_count == 10 }1649 end1650end16511652module TestShell1653 def setup
370 unmodified lines