mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-06 15:12:05 -07:00
Add 'focus' event
Can we find a better name? I have considered the followings. * 'point', because "the pointer" points to the current item. * 'shift', 'switch', 'move', etc. These are not technically correct because the current item can change without cursor movement (--tac, reload, search update) * 'change' is already taken. 'change-current' feels a bit wordy and sounds wrong, 'current-changed' is wordy and doesn't go well with the other event names * 'target', not straightforward Close #3053
This commit is contained in:
@@ -1265,7 +1265,7 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
|
||||
}
|
||||
|
||||
func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts labelOpts, length int, borderShape tui.BorderShape, redrawBorder bool) {
|
||||
if window == nil || render == nil {
|
||||
if window == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1274,6 +1274,9 @@ func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts label
|
||||
if redrawBorder {
|
||||
window.DrawHBorder()
|
||||
}
|
||||
if render == nil {
|
||||
return
|
||||
}
|
||||
var col int
|
||||
if opts.column == 0 {
|
||||
col = util.Max(0, (window.Width()-length)/2)
|
||||
@@ -2616,6 +2619,11 @@ func (t *Terminal) Loop() {
|
||||
}
|
||||
}
|
||||
|
||||
var onFocus []*action
|
||||
if actions, prs := t.keymap[tui.Focus.AsEvent()]; prs {
|
||||
onFocus = actions
|
||||
}
|
||||
|
||||
go func() {
|
||||
var focusedIndex int32 = minItem.Index()
|
||||
var version int64 = -1
|
||||
@@ -2651,7 +2659,11 @@ func (t *Terminal) Loop() {
|
||||
if currentItem != nil {
|
||||
currentIndex = currentItem.Index()
|
||||
}
|
||||
if focusedIndex != currentIndex || version != t.version {
|
||||
focusChanged := focusedIndex != currentIndex
|
||||
if onFocus != nil && focusChanged {
|
||||
t.serverChan <- onFocus
|
||||
}
|
||||
if focusChanged || version != t.version {
|
||||
version = t.version
|
||||
focusedIndex = currentIndex
|
||||
refreshPreview(t.previewOpts.command)
|
||||
|
Reference in New Issue
Block a user