summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-01-23 16:22:25 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-01-23 16:38:24 +0900
commit284d77fe2e41ec69fcc7ca7162bcf9b65b1641be (patch)
tree0dbac33153f7b7b611bc41451e09fdeeb4af4410 /src
parent826178f1e2927ecef8b7699ef1269ba060a0a029 (diff)
downloadfzf-284d77fe2e41ec69fcc7ca7162bcf9b65b1641be.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/options.go2
-rw-r--r--src/terminal.go16
-rw-r--r--src/tui/tui.go1
3 files changed, 17 insertions, 2 deletions
diff --git a/src/options.go b/src/options.go
index fa238d7e..393f5804 100644
--- a/src/options.go
+++ b/src/options.go
@@ -609,6 +609,8 @@ func parseKeyChordsImpl(str string, message string, exit func(string)) map[tui.E
add(tui.Start)
case "load":
add(tui.Load)
+ case "focus":
+ add(tui.Focus)
case "alt-enter", "alt-return":
chords[tui.CtrlAltKey('m')] = key
case "alt-space":
diff --git a/src/terminal.go b/src/terminal.go
index a9565c86..62e80431 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -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)
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 203da76c..a51627fd 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -92,6 +92,7 @@ const (
BackwardEOF
Start
Load
+ Focus
AltBS