mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-23 15:18:29 +00:00
Fix the behavior of change-preview-window action (#3280)
* change-preview-window restores the initial preview window options, and overrides the properties that are specified * However, 'hidden' property is treated differently. It is set to 'false' if the specified properties of the action is non-empty. * cf. toggle-preview takes the "current" preview window options and toggles the 'hidden' property.
This commit is contained in:
parent
e619b7c4f4
commit
94999101e3
@ -1969,25 +1969,25 @@ func postProcessOptions(opts *Options) {
|
|||||||
// Extend the default key map
|
// Extend the default key map
|
||||||
keymap := defaultKeymap()
|
keymap := defaultKeymap()
|
||||||
for key, actions := range opts.Keymap {
|
for key, actions := range opts.Keymap {
|
||||||
var lastChangePreviewWindow *action
|
reordered := []*action{}
|
||||||
for _, act := range actions {
|
for _, act := range actions {
|
||||||
switch act.t {
|
switch act.t {
|
||||||
case actToggleSort:
|
case actToggleSort:
|
||||||
// To display "+S"/"-S" on info line
|
// To display "+S"/"-S" on info line
|
||||||
opts.ToggleSort = true
|
opts.ToggleSort = true
|
||||||
case actChangePreviewWindow:
|
case actTogglePreview, actShowPreview, actHidePreview, actChangePreviewWindow:
|
||||||
lastChangePreviewWindow = act
|
reordered = append(reordered, act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-organize actions so that we only keep the last change-preview-window
|
// Re-organize actions so that we put actions that change the preview window first in the list.
|
||||||
// and it comes first in the list.
|
|
||||||
// * change-preview-window(up,+10)+preview(sleep 3; cat {})+change-preview-window(up,+20)
|
// * change-preview-window(up,+10)+preview(sleep 3; cat {})+change-preview-window(up,+20)
|
||||||
// -> change-preview-window(up,+20)+preview(sleep 3; cat {})
|
// -> change-preview-window(up,+10)+change-preview-window(up,+20)+preview(sleep 3; cat {})
|
||||||
if lastChangePreviewWindow != nil {
|
if len(reordered) > 0 {
|
||||||
reordered := []*action{lastChangePreviewWindow}
|
|
||||||
for _, act := range actions {
|
for _, act := range actions {
|
||||||
if act.t != actChangePreviewWindow {
|
switch act.t {
|
||||||
|
case actTogglePreview, actShowPreview, actHidePreview, actChangePreviewWindow:
|
||||||
|
default:
|
||||||
reordered = append(reordered, act)
|
reordered = append(reordered, act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3523,6 +3523,9 @@ func (t *Terminal) Loop() {
|
|||||||
|
|
||||||
// Split window options
|
// Split window options
|
||||||
tokens := strings.Split(a.a, "|")
|
tokens := strings.Split(a.a, "|")
|
||||||
|
if len(tokens[0]) > 0 && t.initialPreviewOpts.hidden {
|
||||||
|
t.previewOpts.hidden = false
|
||||||
|
}
|
||||||
parsePreviewWindow(&t.previewOpts, tokens[0])
|
parsePreviewWindow(&t.previewOpts, tokens[0])
|
||||||
if len(tokens) > 1 {
|
if len(tokens) > 1 {
|
||||||
a.a = strings.Join(append(tokens[1:], tokens[0]), "|")
|
a.a = strings.Join(append(tokens[1:], tokens[0]), "|")
|
||||||
|
@ -2493,6 +2493,39 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_change_preview_window_rotate_hidden
|
||||||
|
tmux.send_keys "seq 100 | #{FZF} --preview-window hidden --preview 'echo =={}==' --bind '" \
|
||||||
|
"a:change-preview-window(nohidden||down,1|)'", :Enter
|
||||||
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
||||||
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
||||||
|
tmux.send_keys 'a'
|
||||||
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
||||||
|
tmux.send_keys 'a'
|
||||||
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
||||||
|
tmux.send_keys 'a'
|
||||||
|
tmux.until { |lines| assert_includes lines[-2], '==1==' }
|
||||||
|
tmux.send_keys 'a'
|
||||||
|
tmux.until { |lines| refute_includes lines[-2], '==1==' }
|
||||||
|
tmux.send_keys 'a'
|
||||||
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_change_preview_window_rotate_hidden_down
|
||||||
|
tmux.send_keys "seq 100 | #{FZF} --bind '?:change-preview-window:up||down|' --preview 'echo =={}==' --preview-window hidden,down,1", :Enter
|
||||||
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
||||||
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| refute_includes lines[1], '==1==' }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| assert_includes lines[-2], '==1==' }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| refute_includes lines[-2], '==1==' }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| assert_includes lines[1], '==1==' }
|
||||||
|
end
|
||||||
|
|
||||||
def test_ellipsis
|
def test_ellipsis
|
||||||
tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter
|
tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter
|
||||||
tmux.until { |lines| assert_equal 1, lines.match_count }
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user