Skip to content
Myr

Add click-header event for reporting clicks within header (#3768)

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

Sets $FZF_CLICK_HEADER_LINE and $FZF_CLICK_HEADER_COLUMN env vars with coordinates of the last click inside and relative to the header and fires click-header event.

authored by Kuremu · committed by GitHub · parent b6add2a · Browse files · 4 files+47 added−3 removed
This commit

State

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

Trailers

  • Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>

Diff stats

4 files+47 added−3 removed

  • other:+47 added−3 removed

4 files+47 added−3 removed

modified:man/man1/fzf.1+9 added
1276 unmodified lines
1277e.g.1278 \fBfzf --bind space:jump,jump:accept,jump-cancel:abort\fR1279.RE12801281\fIclick-header\fR1282.RS1283Triggered when a mouse click occurs within the header. Sets \fBFZF_CLICK_HEADER_LINE\fR and \fBFZF_CLICK_HEADER_COLUMN\fR environment variables.12841285e.g.1286 \fBprintf "head1\\nhead2" | fzf --header-lines=2 --bind 'click-header:transform-prompt:printf ${FZF_CLICK_HEADER_LINE}x${FZF_CLICK_HEADER_COLUMN}'\fR12871288.RE12891290.SS AVAILABLE ACTIONS:1291A key or an event can be bound to one or more of the following actions.12921293 \fBACTION: DEFAULT BINDINGS (NOTES):
276 unmodified lines
modified:src/tui/tui.go+1 added
128 unmodified lines
129 Zero130 Result131 Jump132 JumpCancel133 ClickHeader134)135136func (t EventType) AsEvent() Event {137 return Event{t, 0, nil}
725 unmodified lines
modified:src/options.go+2 added
706 unmodified lines
707 case "jump":708 add(tui.Jump)709 case "jump-cancel":710 add(tui.JumpCancel)711 case "click-header":712 add(tui.ClickHeader)713 case "alt-enter", "alt-return":714 chords[tui.CtrlAltKey('m')] = key715 case "alt-space":716 chords[tui.AltKey(' ')] = key
1613 unmodified lines
modified:src/terminal.go+35 added-3 removed
296 unmodified lines
297 lastFocus int32298 areaLines int299 areaColumns int300 forcePreview bool301 clickHeaderLine int302 clickHeaderColumn int303}304305type selectedItem struct {306 at time.Time
551 unmodified lines
858 env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))859 env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))860 env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))861 env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1)))862 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine))863 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn))864 return env865}866867func borderLines(shape tui.BorderShape) int {
3136 unmodified lines
4004 break4005 }40064007 if me.Down {4004 mx = util.Constrain(mx-t.promptLen, 0, len(t.input))4005 if my == t.promptLine() && mx >= 0 {4008 mx_cons := util.Constrain(mx-t.promptLen, 0, len(t.input))4009 if my == t.promptLine() && mx_cons >= 0 {4010 // Prompt4007 t.cx = mx + t.xoffset4011 t.cx = mx_cons + t.xoffset4012 } else if my >= min {4013 t.vset(t.offset + my - min)4014 req(reqList)4015 evt := tui.RightClick
6 unmodified lines
4022 evt = tui.SLeftClick4023 }4024 }4025 return doActions(actionsFor(evt))4026 } else {4027 // Header4028 lineOffset := 04029 numLines := t.visibleHeaderLines()4030 if !t.headerFirst {4031 // offset for info line4032 if t.noSeparatorLine() {4033 lineOffset = 14034 } else {4035 lineOffset = 24036 }4037 } else {4038 // adjust for too-small window4039 numItems := t.areaLines - numLines4040 if !t.noSeparatorLine() {4041 numItems -= 14042 }4043 if numItems < 0 {4044 numLines += numItems4045 }4046 }4047 my = util.Constrain(my-lineOffset, -1, numLines)4048 mx -= 2 // offset gutter4049 if my >= 0 && my < numLines && mx >= 0 {4050 t.clickHeaderLine = my + 14051 t.clickHeaderColumn = mx + 14052 return doActions(actionsFor(tui.ClickHeader))4053 }4054 }4055 }4056 case actReload, actReloadSync:4057 t.failed = nil
279 unmodified lines