m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-13 22:03:47 -05:00

Fix {q} in preview window affected by 'search' action

This commit is contained in:
Junegunn Choi
2025-02-18 10:08:47 +09:00
parent 01d9d9c8c8
commit f975b40236
2 changed files with 20 additions and 4 deletions

View File

@@ -638,6 +638,7 @@ type previewRequest struct {
scrollOffset int
list []*Item
env []string
query string
}
type previewResult struct {
@@ -4385,6 +4386,7 @@ func (t *Terminal) Loop() error {
var items []*Item
var commandTemplate string
var env []string
var query string
initialOffset := 0
t.previewBox.Wait(func(events *util.Events) {
for req, value := range *events {
@@ -4398,6 +4400,7 @@ func (t *Terminal) Loop() error {
initialOffset = request.scrollOffset
items = request.list
env = request.env
query = request.query
}
}
events.Clear()
@@ -4411,8 +4414,7 @@ func (t *Terminal) Loop() error {
version++
// We don't display preview window if no match
if items[0] != nil {
_, query := t.Input()
command, tempFiles := t.replacePlaceholder(commandTemplate, false, string(query), items)
command, tempFiles := t.replacePlaceholder(commandTemplate, false, query, items)
cmd := t.executor.ExecCommand(command, true)
cmd.Env = env
@@ -4540,7 +4542,7 @@ func (t *Terminal) Loop() error {
if len(command) > 0 && t.canPreview() {
_, list := t.buildPlusList(command, false)
t.cancelPreview()
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environForPreview()})
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environForPreview(), string(t.input)})
}
}
@@ -4972,7 +4974,7 @@ func (t *Terminal) Loop() error {
if valid {
t.cancelPreview()
t.previewBox.Set(reqPreviewEnqueue,
previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environForPreview()})
previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environForPreview(), string(t.input)})
}
} else {
// Discard the preview content so that it won't accidentally appear