Skip to content
Myr

Fix the behavior of change-preview-window action (#3280)

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

* 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.

authored by Junegunn Choi · committed by Junegunn Choi · parent e619b7c · Browse files · 3 files+45 added−9 removed
This commit

State

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

Diff stats

3 files+45 added−9 removed

  • tests:+33 added−0 removed
  • other:+12 added−9 removed

3 files+45 added−9 removed

modified:src/options.go+9 added-9 removed
1967 unmodified lines
19681969 // Extend the default key map1970 keymap := defaultKeymap()1971 for key, actions := range opts.Keymap {1972 var lastChangePreviewWindow *action1972 reordered := []*action{}1973 for _, act := range actions {1974 switch act.t {1975 case actToggleSort:1976 // To display "+S"/"-S" on info line1977 opts.ToggleSort = true1978 case actChangePreviewWindow:1979 lastChangePreviewWindow = act1978 case actTogglePreview, actShowPreview, actHidePreview, actChangePreviewWindow:1979 reordered = append(reordered, act)1980 }1981 }19821983 // Re-organize actions so that we only keep the last change-preview-window1984 // and it comes first in the list.1983 // Re-organize actions so that we put actions that change the preview window first in the list.1984 // * change-preview-window(up,+10)+preview(sleep 3; cat {})+change-preview-window(up,+20)1986 // -> change-preview-window(up,+20)+preview(sleep 3; cat {})1987 if lastChangePreviewWindow != nil {1988 reordered := []*action{lastChangePreviewWindow}1985 // -> change-preview-window(up,+10)+change-preview-window(up,+20)+preview(sleep 3; cat {})1986 if len(reordered) > 0 {1987 for _, act := range actions {1990 if act.t != actChangePreviewWindow {1988 switch act.t {1989 case actTogglePreview, actShowPreview, actHidePreview, actChangePreviewWindow:1990 default:1991 reordered = append(reordered, act)1992 }1993 }1994 actions = reordered
87 unmodified lines
modified:src/terminal.go+3 added
3521 unmodified lines
3522 t.previewOpts = t.initialPreviewOpts35233524 // Split window options3525 tokens := strings.Split(a.a, "|")3526 if len(tokens[0]) > 0 && t.initialPreviewOpts.hidden {3527 t.previewOpts.hidden = false3528 }3529 parsePreviewWindow(&t.previewOpts, tokens[0])3530 if len(tokens) > 1 {3531 a.a = strings.Join(append(tokens[1:], tokens[0]), "|")3532 }
166 unmodified lines
modified:test/test_go.rb+33 added
2491 unmodified lines
2492 tmux.send_keys 'a'2493 end2494 end24952496 def test_change_preview_window_rotate_hidden2497 tmux.send_keys "seq 100 | #{FZF} --preview-window hidden --preview 'echo =={}==' --bind '" \2498 "a:change-preview-window(nohidden||down,1|)'", :Enter2499 tmux.until { |lines| assert_equal 100, lines.match_count }2500 tmux.until { |lines| refute_includes lines[1], '==1==' }2501 tmux.send_keys 'a'2502 tmux.until { |lines| assert_includes lines[1], '==1==' }2503 tmux.send_keys 'a'2504 tmux.until { |lines| refute_includes lines[1], '==1==' }2505 tmux.send_keys 'a'2506 tmux.until { |lines| assert_includes lines[-2], '==1==' }2507 tmux.send_keys 'a'2508 tmux.until { |lines| refute_includes lines[-2], '==1==' }2509 tmux.send_keys 'a'2510 tmux.until { |lines| assert_includes lines[1], '==1==' }2511 end25122513 def test_change_preview_window_rotate_hidden_down2514 tmux.send_keys "seq 100 | #{FZF} --bind '?:change-preview-window:up||down|' --preview 'echo =={}==' --preview-window hidden,down,1", :Enter2515 tmux.until { |lines| assert_equal 100, lines.match_count }2516 tmux.until { |lines| refute_includes lines[1], '==1==' }2517 tmux.send_keys '?'2518 tmux.until { |lines| assert_includes lines[1], '==1==' }2519 tmux.send_keys '?'2520 tmux.until { |lines| refute_includes lines[1], '==1==' }2521 tmux.send_keys '?'2522 tmux.until { |lines| assert_includes lines[-2], '==1==' }2523 tmux.send_keys '?'2524 tmux.until { |lines| refute_includes lines[-2], '==1==' }2525 tmux.send_keys '?'2526 tmux.until { |lines| assert_includes lines[1], '==1==' }2527 end25282529 def test_ellipsis2530 tmux.send_keys 'seq 1000 | tr "\n" , | fzf --ellipsis=SNIPSNIP -e -q500', :Enter2531 tmux.until { |lines| assert_equal 1, lines.match_count }2532 tmux.until { |lines| assert_match(/^> SNIPSNIP.*SNIPSNIP$/, lines[-3]) }
872 unmodified lines