Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputField SetText append text instead of replacing it #1025

Closed
CarlosMontilla opened this issue Sep 14, 2024 · 1 comment
Closed

InputField SetText append text instead of replacing it #1025

CarlosMontilla opened this issue Sep 14, 2024 · 1 comment

Comments

@CarlosMontilla
Copy link

Hello,

First of all I would like to thank you for this wonderful library.

Recently I updated to the latest release 20240818110301-fd649dbf1223 from the previous one 20230325211341-281d14d896d7.

And I've encountered a strange behaviour with the InputField.SetText method in the latest version. If I take the InputField demo and add 2 consecutive SetText("12"), the resulting input field text contains the string "1212". So the second SetText had the effect of appending the string instead to the current text field of replacing it. While in the previous version, I encountered the behaviour I would expect. The second SetText replaced the string.

I leave the code below and a screenshot of what I get

// Demo code for the InputField primitive.
package main

import (
        "github.com/gdamore/tcell/v2"
        "github.com/rivo/tview"
)

func main() {
        app := tview.NewApplication()
        inputField := tview.NewInputField().
                SetLabel("Enter a number: ").
                SetPlaceholder("E.g. 1234").
                SetFieldWidth(10).
                SetAcceptanceFunc(tview.InputFieldInteger).
                SetDoneFunc(func(key tcell.Key) {
                        app.Stop()
                })

        inputField.SetText("12")
        inputField.SetText("12")
        if err := app.SetRoot(inputField, true).EnableMouse(true).Run(); err != nil {
                panic(err)
        }
}

Latest version:
image

Previous version:
image

I will keep looking to see if I find the cause of this change of behaviour, but maybe you can spot the problem faster than me.

Thank you for your support

@rivo rivo closed this as completed in 1ad6dae Sep 21, 2024
@rivo
Copy link
Owner

rivo commented Sep 21, 2024

Thanks. The latest commit should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants