summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-04-10 20:11:47 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-04-10 20:17:12 +0900
commita4745626dd5c5f697dbbc5e3aa1796d5016c1faf (patch)
tree18cb90f4fc912dee09880414486fe07f0f34b46d /src
parent17bb7ad2784afdfc99beeec9e0a58f8dae12748a (diff)
Add jump and jump-cancel events
Close #3412 # Default behavior fzf --bind space:jump # Same as jump-accept action fzf --bind space:jump,jump:accept # Accept on jump, abort on cancel fzf --bind space:jump,jump:accept,jump-cancel:abort # Change header on jump-cancel fzf --bind 'space:change-header(Type jump label)+jump,jump-cancel:change-header:Jump cancelled'
Diffstat (limited to 'src')
-rw-r--r--src/options.go4
-rw-r--r--src/terminal.go20
-rw-r--r--src/tui/tui.go2
3 files changed, 18 insertions, 8 deletions
diff --git a/src/options.go b/src/options.go
index 5c73aee7..ffa3878f 100644
--- a/src/options.go
+++ b/src/options.go
@@ -698,6 +698,10 @@ func parseKeyChordsImpl(str string, message string, exit func(string)) map[tui.E
add(tui.One)
case "zero":
add(tui.Zero)
+ case "jump":
+ add(tui.Jump)
+ case "jump-cancel":
+ add(tui.JumpCancel)
case "alt-enter", "alt-return":
chords[tui.CtrlAltKey('m')] = key
case "alt-space":
diff --git a/src/terminal.go b/src/terminal.go
index 2289a7f9..5057e931 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -4108,6 +4108,9 @@ func (t *Terminal) Loop() {
// Break out of jump mode if any action is submitted to the server
if t.jumping != jumpDisabled {
t.jumping = jumpDisabled
+ if acts, prs := t.keymap[tui.JumpCancel.AsEvent()]; prs && !doActions(acts) {
+ continue
+ }
req(reqList)
}
if len(actions) == 0 {
@@ -4121,19 +4124,17 @@ func (t *Terminal) Loop() {
t.truncateQuery()
queryChanged = string(previousInput) != string(t.input)
changed = changed || queryChanged
- if onChanges, prs := t.keymap[tui.Change.AsEvent()]; queryChanged && prs {
- if !doActions(onChanges) {
- continue
- }
+ if onChanges, prs := t.keymap[tui.Change.AsEvent()]; queryChanged && prs && !doActions(onChanges) {
+ continue
}
- if onEOFs, prs := t.keymap[tui.BackwardEOF.AsEvent()]; beof && prs {
- if !doActions(onEOFs) {
- continue
- }
+ if onEOFs, prs := t.keymap[tui.BackwardEOF.AsEvent()]; beof && prs && !doActions(onEOFs) {
+ continue
}
} else {
+ jumpEvent := tui.JumpCancel
if event.Type == tui.Rune {
if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {
+ jumpEvent = tui.Jump
t.cy = idx + t.offset
if t.jumping == jumpAcceptEnabled {
req(reqClose)
@@ -4141,6 +4142,9 @@ func (t *Terminal) Loop() {
}
}
t.jumping = jumpDisabled
+ if acts, prs := t.keymap[jumpEvent.AsEvent()]; prs && !doActions(acts) {
+ continue
+ }
req(reqList)
}
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 022fae34..729146cc 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -108,6 +108,8 @@ const (
One
Zero
Result
+ Jump
+ JumpCancel
AltBS