From 5b57d24afd4e3dec029bc32528d2d6e4dc8a3e64 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Wed, 23 Oct 2024 08:51:01 -0500 Subject: textinput: make completions run async with cancellation Make the Completer interface accept a context.Context. Provide a cancellation feature on text input tab completion to cancel an inflight completion command. This is particularly useful for address book completion if the user has specified a network-accessing command, eg carddav-query. The command is started according to the completion delay, but is cancellable if another request comes in. We also check for cancellation after the request is complete to ensure we only show valid completion results. Changelog-changed: Tab completions for text fields are run asynchronously. In-flight requests are cancelled when new input arrives. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- commands/completion_helpers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'commands/completion_helpers.go') diff --git a/commands/completion_helpers.go b/commands/completion_helpers.go index 8d293a32..6017035e 100644 --- a/commands/completion_helpers.go +++ b/commands/completion_helpers.go @@ -1,6 +1,7 @@ package commands import ( + "context" "fmt" "net/mail" "strings" @@ -30,7 +31,7 @@ func GetAddress(search string) []string { }) if cmpl != nil { - addrList, _ := cmpl.ForHeader("to")(search) + addrList, _ := cmpl.ForHeader("to")(context.Background(), search) for _, full := range addrList { addr, err := mail.ParseAddress(full.Value) if err != nil { -- cgit