mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #180] Panic if you type anything else after calling InputField.SetText("") #144
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#144
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jonathanpittman on GitHub (Nov 7, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/180
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...
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?
@rivo commented on GitHub (Nov 10, 2018):
Thanks for spotting this. The cursor position must of course be adjusted after calling
SetText(), too. I just fixed this. Let me know if it works for you now.@jonathanpittman commented on GitHub (Nov 14, 2018):
It does work. Thanks!