mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-11 00:00:55 +00:00
Add click-header event for reporting clicks within header (#3768)
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. Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
parent
b6add2a257
commit
7b98c2c653
@ -1278,6 +1278,15 @@ e.g.
|
|||||||
\fBfzf --bind space:jump,jump:accept,jump-cancel:abort\fR
|
\fBfzf --bind space:jump,jump:accept,jump-cancel:abort\fR
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
\fIclick-header\fR
|
||||||
|
.RS
|
||||||
|
Triggered when a mouse click occurs within the header. Sets \fBFZF_CLICK_HEADER_LINE\fR and \fBFZF_CLICK_HEADER_COLUMN\fR environment variables.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
\fBprintf "head1\\nhead2" | fzf --header-lines=2 --bind 'click-header:transform-prompt:printf ${FZF_CLICK_HEADER_LINE}x${FZF_CLICK_HEADER_COLUMN}'\fR
|
||||||
|
|
||||||
|
.RE
|
||||||
|
|
||||||
.SS AVAILABLE ACTIONS:
|
.SS AVAILABLE ACTIONS:
|
||||||
A key or an event can be bound to one or more of the following actions.
|
A key or an event can be bound to one or more of the following actions.
|
||||||
|
|
||||||
|
@ -708,6 +708,8 @@ func parseKeyChordsImpl(str string, message string, exit func(string)) map[tui.E
|
|||||||
add(tui.Jump)
|
add(tui.Jump)
|
||||||
case "jump-cancel":
|
case "jump-cancel":
|
||||||
add(tui.JumpCancel)
|
add(tui.JumpCancel)
|
||||||
|
case "click-header":
|
||||||
|
add(tui.ClickHeader)
|
||||||
case "alt-enter", "alt-return":
|
case "alt-enter", "alt-return":
|
||||||
chords[tui.CtrlAltKey('m')] = key
|
chords[tui.CtrlAltKey('m')] = key
|
||||||
case "alt-space":
|
case "alt-space":
|
||||||
|
@ -298,6 +298,8 @@ type Terminal struct {
|
|||||||
areaLines int
|
areaLines int
|
||||||
areaColumns int
|
areaColumns int
|
||||||
forcePreview bool
|
forcePreview bool
|
||||||
|
clickHeaderLine int
|
||||||
|
clickHeaderColumn int
|
||||||
}
|
}
|
||||||
|
|
||||||
type selectedItem struct {
|
type selectedItem struct {
|
||||||
@ -857,6 +859,8 @@ func (t *Terminal) environ() []string {
|
|||||||
env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))
|
env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))
|
||||||
env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))
|
env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))
|
||||||
env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1)))
|
env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1)))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn))
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4001,10 +4005,10 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if me.Down {
|
if me.Down {
|
||||||
mx = util.Constrain(mx-t.promptLen, 0, len(t.input))
|
mx_cons := util.Constrain(mx-t.promptLen, 0, len(t.input))
|
||||||
if my == t.promptLine() && mx >= 0 {
|
if my == t.promptLine() && mx_cons >= 0 {
|
||||||
// Prompt
|
// Prompt
|
||||||
t.cx = mx + t.xoffset
|
t.cx = mx_cons + t.xoffset
|
||||||
} else if my >= min {
|
} else if my >= min {
|
||||||
t.vset(t.offset + my - min)
|
t.vset(t.offset + my - min)
|
||||||
req(reqList)
|
req(reqList)
|
||||||
@ -4019,6 +4023,34 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return doActions(actionsFor(evt))
|
return doActions(actionsFor(evt))
|
||||||
|
} else {
|
||||||
|
// Header
|
||||||
|
lineOffset := 0
|
||||||
|
numLines := t.visibleHeaderLines()
|
||||||
|
if !t.headerFirst {
|
||||||
|
// offset for info line
|
||||||
|
if t.noSeparatorLine() {
|
||||||
|
lineOffset = 1
|
||||||
|
} else {
|
||||||
|
lineOffset = 2
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// adjust for too-small window
|
||||||
|
numItems := t.areaLines - numLines
|
||||||
|
if !t.noSeparatorLine() {
|
||||||
|
numItems -= 1
|
||||||
|
}
|
||||||
|
if numItems < 0 {
|
||||||
|
numLines += numItems
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my = util.Constrain(my-lineOffset, -1, numLines)
|
||||||
|
mx -= 2 // offset gutter
|
||||||
|
if my >= 0 && my < numLines && mx >= 0 {
|
||||||
|
t.clickHeaderLine = my + 1
|
||||||
|
t.clickHeaderColumn = mx + 1
|
||||||
|
return doActions(actionsFor(tui.ClickHeader))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case actReload, actReloadSync:
|
case actReload, actReloadSync:
|
||||||
|
@ -130,6 +130,7 @@ const (
|
|||||||
Result
|
Result
|
||||||
Jump
|
Jump
|
||||||
JumpCancel
|
JumpCancel
|
||||||
|
ClickHeader
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t EventType) AsEvent() Event {
|
func (t EventType) AsEvent() Event {
|
||||||
|
Loading…
Reference in New Issue
Block a user