Skip to content

Panic if you type anything else after calling InputField.SetText("") #180

@jonathanpittman

Description

@jonathanpittman

I may simply be doing this wrong. I am using an InputField to implement a command prompt of sorts (e.g. IRC command and message entry). In the InputField's DoneFunc, I am doing this...

case tcell.KeyEnter:
	defer cmdLine.SetText("")

So that regardless of what happens next with the value of the existing text, enter will "clear" the text of the input field to be ready for a new command. This causes a panic as soon as you begin to type some other character after SetText("").

https://github.com/rivo/tview/blob/master/inputfield.go#L365
newText := i.text[:i.cursorPos] + string(r) + i.text[i.cursorPos:]

If I remove the SetText(""), then no panic occurs, but the text remains in the input field. I can hold the delete/backspace key to clear the text and type something else in its place without panic.
Is there a better approach to what I am doing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions