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
Provenance
- Commit
7941129- Tree
b540410- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
069d71a
6 files changed+84 added−3 removed
modified:man/man1/fzf.1+8 added
1680 unmodified lines1681 echo "$FZF_CLICK_HEADER_WORD> "1682 )'\fR1683 .RE1684 1685+\fIclick\-footer\fR1686+.RS1687+Triggered when a mouse click occurs within the footer. Sets1688+\fBFZF_CLICK_FOOTER_LINE\fR and \fBFZF_CLICK_FOOTER_COLUMN\fR environment1689+variables starting from 1. It optionally sets \fBFZF_CLICK_FOOTER_WORD\fR1690+if clicked on a word.1691+.RE1692+1693 .SS AVAILABLE ACTIONS:1694 A key or an event can be bound to one or more of the following actions.1695 1696 \fBACTION: DEFAULT BINDINGS (NOTES):328 unmodified linesmodified:src/tui/eventtype_string.go+4 added-3 removed
108 unmodified lines109 _ = 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 }116 116-const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlDeleteCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltCtrlAltInvalidFatalBracketedPasteBeginBracketedPasteEndMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderMulti"117+const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlDeleteCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltCtrlAltInvalidFatalBracketedPasteBeginBracketedPasteEndMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderClickFooterMulti"118 118-var _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}119+var _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}120 121 func (i EventType) String() string {122 if i < 0 || i >= EventType(len(_EventType_index)-1) {123 return "EventType(" + strconv.FormatInt(int64(i), 10) + ")"3 unmodified linesmodified:src/tui/tui.go+1 added
130 unmodified lines131 Result132 Jump133 JumpCancel134 ClickHeader135+ ClickFooter136 Multi137 )138 139 func (t EventType) AsEvent() Event {1014 unmodified linesmodified:src/options.go+2 added
1006 unmodified lines1007 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')] = key2602 unmodified linesmodified:src/terminal.go+48 added
420 unmodified lines421 areaColumns int422 forcePreview bool423 clickHeaderLine int424 clickHeaderColumn int425+ clickFooterLine int426+ clickFooterColumn int427 proxyScript string428 numLinesCache map[int32]numLinesCacheValue429 }430 829 unmodified lines1260 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)1268 1269 // Add preview environment variables if preview is enabled1270 pwindowSize := t.pwindowSize()1271 if pwindowSize.Lines > 0 {366 unmodified lines1638 if len(footer) > 0 {1639 lines = strings.Split(strings.TrimSuffix(footer, "\n"), "\n")1640 }1641 t.footer = lines1642+ t.clickFooterLine = 01643+ t.clickFooterColumn = 01644 }1645 1646 // UpdateHeader updates the header1647 func (t *Terminal) UpdateHeader(header []string) {3161 unmodified lines4809 }4810 return env4811 }4812 4813+func (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+ }4819+4820+ // 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)4829+4830+ // 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+}4841+4842 // Loop is called to start Terminal I/O4843 func (t *Terminal) Loop() error {4844 // prof := profile.Start(profile.ProfilePath("/tmp/"))4845 fitpad := <-t.startChan1569 unmodified lines6415 t.clickHeaderColumn = mx + 16416 return doActions(actionsFor(tui.ClickHeader))6417 }6418 6419+ // 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+ }6430+6431 // Ignored6432 if !t.window.Enclose(my, mx) && !barDragging {6433 break6434 }542 unmodified linesmodified:CHANGELOG.md+21 added
1 CHANGELOG2 =========3 4+0.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 fixes24+25 0.64.026 ------27 - Added `multi` event that is triggered when the multi-selection has changed.28 ```sh2732 unmodified lines