about summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
authorParasrah <dev@parasrah.com>2022-01-06 21:54:28 -0700
committerRobin Jarry <robin@jarry.cc>2022-01-07 13:54:10 +0100
commit71eda7d37c8ef38502c360b518fcbf5960497eea (patch)
tree07b9383865f65934001378f170c942242bc0f054 /lib/ui
parentb19b844a6326793f078b4a03eaf63ca96528796e (diff)
downloadaerc-71eda7d37c8ef38502c360b518fcbf5960497eea.tar.gz
completions: add support for completing multiple addresses HEAD master
as per the discussion https://lists.sr.ht/~sircmpwn/aerc/patches/15367
this handles completions in `completer/completer.go` by enabling the
completer to return a `prefix` that will be prepended to the selected
completion candidate.
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/textinput.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 9daae3a..cd31d26 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -24,8 +24,9 @@ type TextInput struct {
 	scroll            int
 	text              []rune
 	change            []func(ti *TextInput)
-	tabcomplete       func(s string) []string
+	tabcomplete       func(s string) ([]string, string)
 	completions       []string
+	prefix            string
 	completeIndex     int
 	completeDelay     time.Duration
 	completeDebouncer *time.Timer
@@ -55,7 +56,7 @@ func (ti *TextInput) Prompt(prompt string) *TextInput {
 }
 
 func (ti *TextInput) TabComplete(
-	tabcomplete func(s string) []string, d time.Duration) *TextInput {
+	tabcomplete func(s string) ([]string, string), d time.Duration) *TextInput {
 	ti.tabcomplete = tabcomplete
 	ti.completeDelay = d
 	return ti
@@ -129,7 +130,7 @@ func (ti *TextInput) drawPopover(ctx *Context) {
 			ti.Invalidate()
 		},
 		onStem: func(stem string) {
-			ti.Set(stem + ti.StringRight())
+			ti.Set(ti.prefix + stem + ti.StringRight())
 			ti.Invalidate()
 		},
 		uiConfig: ti.uiConfig,
@@ -251,7 +252,7 @@ func (ti *TextInput) backspace() {
 
 func (ti *TextInput) executeCompletion() {
 	if len(ti.completions) > 0 {
-		ti.Set(ti.completions[ti.completeIndex] + ti.StringRight())
+		ti.Set(ti.prefix + ti.completions[ti.completeIndex] + ti.StringRight())
 	}
 }
 
@@ -286,7 +287,7 @@ func (ti *TextInput) showCompletions() {
 		// no completer
 		return
 	}
-	ti.completions = ti.tabcomplete(ti.StringLeft())
+	ti.completions, ti.prefix = ti.tabcomplete(ti.StringLeft())
 	ti.completeIndex = -1
 	ti.Invalidate()
 }
' href='#n210'>210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384