Skip to content
Myr

Add 'click-footer' event

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 069d71a · Browse files · 6 files+84 added−3 removed
This commit

State

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

Diff stats

6 files+84 added−3 removed

  • other:+84 added−3 removed

6 files+84 added−3 removed

modified:man/man1/fzf.1+8 added
1680 unmodified lines
1681 echo "$FZF_CLICK_HEADER_WORD> "1682 )'\fR1683.RE16841685\fIclick\-footer\fR1686.RS1687Triggered when a mouse click occurs within the footer. Sets1688\fBFZF_CLICK_FOOTER_LINE\fR and \fBFZF_CLICK_FOOTER_COLUMN\fR environment1689variables starting from 1. It optionally sets \fBFZF_CLICK_FOOTER_WORD\fR1690if clicked on a word.1691.RE16921693.SS AVAILABLE ACTIONS:1694A key or an event can be bound to one or more of the following actions.16951696 \fBACTION: DEFAULT BINDINGS (NOTES):
328 unmodified lines
modified:src/tui/eventtype_string.go+4 added-3 removed
108 unmodified lines
109 _ = x[Result-98]110 _ = x[Jump-99]111 _ = x[JumpCancel-100]112 _ = x[ClickHeader-101]113 _ = x[Multi-102]113 _ = x[ClickFooter-102]114 _ = x[Multi-103]115}116116const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlDeleteCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltCtrlAltInvalidFatalBracketedPasteBeginBracketedPasteEndMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderMulti"117const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlDeleteCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltCtrlAltInvalidFatalBracketedPasteBeginBracketedPasteEndMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderClickFooterMulti"118118var _EventType_index = [...]uint16{0, 4, 9, 14, 19, 24, 29, 34, 39, 44, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97, 102, 107, 112, 117, 122, 127, 132, 135, 144, 154, 167, 183, 192, 201, 209, 218, 224, 230, 238, 240, 244, 248, 253, 257, 260, 266, 273, 282, 291, 301, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 333, 336, 339, 351, 356, 363, 370, 378, 388, 400, 412, 425, 428, 435, 442, 447, 466, 483, 488, 499, 508, 518, 528, 539, 547, 557, 566, 577, 592, 609, 615, 621, 632, 637, 641, 646, 649, 653, 659, 663, 673, 684, 689}119var _EventType_index = [...]uint16{0, 4, 9, 14, 19, 24, 29, 34, 39, 44, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97, 102, 107, 112, 117, 122, 127, 132, 135, 144, 154, 167, 183, 192, 201, 209, 218, 224, 230, 238, 240, 244, 248, 253, 257, 260, 266, 273, 282, 291, 301, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 333, 336, 339, 351, 356, 363, 370, 378, 388, 400, 412, 425, 428, 435, 442, 447, 466, 483, 488, 499, 508, 518, 528, 539, 547, 557, 566, 577, 592, 609, 615, 621, 632, 637, 641, 646, 649, 653, 659, 663, 673, 684, 695, 700}120121func (i EventType) String() string {122 if i < 0 || i >= EventType(len(_EventType_index)-1) {123 return "EventType(" + strconv.FormatInt(int64(i), 10) + ")"
3 unmodified lines
modified:src/tui/tui.go+1 added
130 unmodified lines
131 Result132 Jump133 JumpCancel134 ClickHeader135 ClickFooter136 Multi137)138139func (t EventType) AsEvent() Event {
1014 unmodified lines
modified:src/options.go+2 added
1006 unmodified lines
1007 case "jump-cancel":1008 add(tui.JumpCancel)1009 case "click-header":1010 add(tui.ClickHeader)1011 case "click-footer":1012 add(tui.ClickFooter)1013 case "multi":1014 add(tui.Multi)1015 case "alt-enter", "alt-return":1016 chords[tui.CtrlAltKey('m')] = key
2602 unmodified lines
modified:src/terminal.go+48 added
420 unmodified lines
421 areaColumns int422 forcePreview bool423 clickHeaderLine int424 clickHeaderColumn int425 clickFooterLine int426 clickFooterColumn int427 proxyScript string428 numLinesCache map[int32]numLinesCacheValue429}430
829 unmodified lines
1260 env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))1261 env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1)))1262 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine))1263 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn))1264 env = append(env, fmt.Sprintf("FZF_CLICK_FOOTER_LINE=%d", t.clickFooterLine))1265 env = append(env, fmt.Sprintf("FZF_CLICK_FOOTER_COLUMN=%d", t.clickFooterColumn))1266 env = t.addClickHeaderWord(env)1267 env = t.addClickFooterWord(env)12681269 // Add preview environment variables if preview is enabled1270 pwindowSize := t.pwindowSize()1271 if pwindowSize.Lines > 0 {
366 unmodified lines
1638 if len(footer) > 0 {1639 lines = strings.Split(strings.TrimSuffix(footer, "\n"), "\n")1640 }1641 t.footer = lines1642 t.clickFooterLine = 01643 t.clickFooterColumn = 01644}16451646// UpdateHeader updates the header1647func (t *Terminal) UpdateHeader(header []string) {
3161 unmodified lines
4809 }4810 return env4811}48124813func (t *Terminal) addClickFooterWord(env []string) []string {4814 clickFooterLine := t.clickFooterLine - 14815 if clickFooterLine < 0 || clickFooterLine >= len(t.footer) {4816 // Never clicked on the footer4817 return env4818 }48194820 // NOTE: Unlike in click-header, we don't use --delimiter here, since we're4821 // only interested in the word, not nth. Does this make sense?4822 words := Tokenize(t.footer[clickFooterLine], Delimiter{})4823 colNum := t.clickFooterColumn - 14824 for _, token := range words {4825 prefixWidth := int(token.prefixLength)4826 word := token.text.ToString()4827 trimmed := strings.TrimRightFunc(word, unicode.IsSpace)4828 trimWidth, _ := util.RunesWidth([]rune(trimmed), prefixWidth, t.tabstop, math.MaxInt32)48294830 // Find the position of the first non-space character in the word4831 minPos := strings.IndexFunc(trimmed, func(r rune) bool {4832 return !unicode.IsSpace(r)4833 })4834 if colNum >= minPos && colNum >= prefixWidth && colNum < prefixWidth+trimWidth {4835 env = append(env, fmt.Sprintf("FZF_CLICK_FOOTER_WORD=%s", trimmed))4836 return env4837 }4838 }4839 return env4840}48414842// Loop is called to start Terminal I/O4843func (t *Terminal) Loop() error {4844 // prof := profile.Start(profile.ProfilePath("/tmp/"))4845 fitpad := <-t.startChan
1569 unmodified lines
6415 t.clickHeaderColumn = mx + 16416 return doActions(actionsFor(tui.ClickHeader))6417 }64186419 // Inside the footer window6420 if clicked && t.footerWindow != nil && t.footerWindow.Enclose(my, mx) {6421 mx -= t.footerWindow.Left() + t.headerIndent(t.footerBorderShape)6422 my -= t.footerWindow.Top()6423 if mx < 0 {6424 break6425 }6426 t.clickFooterLine = my + 16427 t.clickFooterColumn = mx + 16428 return doActions(actionsFor(tui.ClickFooter))6429 }64306431 // Ignored6432 if !t.window.Enclose(my, mx) && !barDragging {6433 break6434 }
542 unmodified lines
modified:CHANGELOG.md+21 added
1CHANGELOG2=========340.65.05------6- Added `click-footer` event that is triggered when the footer section is clicked. When the event is triggered, the following environment variables are set:7 - `$FZF_CLICK_FOOTER_COLUMN` - clicked column (1-based)8 - `$FZF_CLICK_FOOTER_LINE` - clicked line (1-based)9 - `$FZF_CLICK_FOOTER_WORD` - the word under the cursor10 ```sh11 fzf --footer $'[Edit] [View]\n[Copy to clipboard]' \12 --with-shell 'bash -c' \13 --bind 'click-footer:transform:14 [[ $FZF_CLICK_FOOTER_WORD =~ Edit ]] && echo "execute:vim \{}"15 [[ $FZF_CLICK_FOOTER_WORD =~ View ]] && echo "execute:view \{}"16 (( FZF_CLICK_FOOTER_LINE == 2 )) && (( FZF_CLICK_FOOTER_COLUMN < 20 )) &&17 echo "execute-silent(echo -n \{} | pbcopy)+bell"18 '19 ```20- Added support for `{*n}` and `{*nf}` placeholder.21 - `{*n}` evaluates to the zero-based ordinal index of all matched items.22 - `{*nf}` evaluates to the temporary file containing that.23- Bug fixes24250.64.026------27- Added `multi` event that is triggered when the multi-selection has changed.28 ```sh
2732 unmodified lines