summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-07-26 14:29:40 +0100
committerDrew DeVault <sir@cmpwn.com>2019-07-26 14:39:42 -0400
commitcded067bc3919a77b17feedd877e4590e7c95f4a (patch)
treef359c28abd705167e3bf013faf8d4d1af4887f29 /widgets
parentaabe3d9b3a58efd9f0ad9b39917b85092d0955a1 (diff)
downloadaerc-cded067bc3919a77b17feedd877e4590e7c95f4a.tar.gz
Add tab completion to textinputs
This adds tab completion to textinput components. They can be configured
with a completion function. This function is called when the user
presses <tab>. The first completion is initially shown to the user
inserted into the text. Repeated presses of <tab> or <backtab> cycle
through the completions list. The completions list is invalidated when
any other non-tab-like key is pressed.

Also changed is some logic for current completion generation so that
all available commands are returned when <tab> is pressed with no
current text and similarly for arguments of commands.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/exline.go8
1 files changed, 1 insertions, 7 deletions
diff --git a/widgets/exline.go b/widgets/exline.go
index b7b4e3d..4791ae9 100644
--- a/widgets/exline.go
+++ b/widgets/exline.go
@@ -20,7 +20,7 @@ func NewExLine(commit func(cmd string), cancel func(),
 	tabcomplete func(cmd string) []string,
 	cmdHistory lib.History) *ExLine {
 
-	input := ui.NewTextInput("").Prompt(":")
+	input := ui.NewTextInput("").Prompt(":").TabComplete(tabcomplete)
 	exline := &ExLine{
 		cancel:      cancel,
 		commit:      commit,
@@ -64,12 +64,6 @@ func (ex *ExLine) Event(event tcell.Event) bool {
 			ex.input.Focus(false)
 			ex.cmdHistory.Reset()
 			ex.cancel()
-		case tcell.KeyTab:
-			complete := ex.tabcomplete(ex.input.StringLeft())
-			if len(complete) == 1 {
-				ex.input.Set(complete[0] + " " + ex.input.StringRight())
-			}
-			ex.Invalidate()
 		default:
 			return ex.input.Event(event)
 		}
74' href='#n174'>174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 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