[GH-ISSUE #892] Controlling position of cursor in InputField #650

Open
opened 2026-03-04 01:06:46 +03:00 by kerem · 2 comments
Owner

Originally created by @paololazzari on GitHub (Sep 28, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/892

Consider:

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	inputField := tview.NewInputField().
		SetText(">>>>>> X <<<<<<")

	if err := app.SetRoot(inputField, true).SetFocus(inputField).Run(); err != nil {
		panic(err)
	}
}

how can I change the position of the cursor so that when I start typing it types right in the middle of the string (where X is) ?

Originally created by @paololazzari on GitHub (Sep 28, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/892 Consider: ```go package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() inputField := tview.NewInputField(). SetText(">>>>>> X <<<<<<") if err := app.SetRoot(inputField, true).SetFocus(inputField).Run(); err != nil { panic(err) } } ``` how can I change the position of the cursor so that when I start typing it types right in the middle of the string (where X is) ?
Author
Owner

@paololazzari commented on GitHub (Sep 29, 2023):

Thanks @digitallyserviced ,

would it be unreasonable to request that SetCursorPos is added to tview ? Are there any reasons not to add this functionality?

<!-- gh-comment-id:1740375698 --> @paololazzari commented on GitHub (Sep 29, 2023): Thanks @digitallyserviced , would it be unreasonable to request that `SetCursorPos` is added to `tview` ? Are there any reasons not to add this functionality?
Author
Owner

@rivo commented on GitHub (Sep 29, 2023):

would it be unreasonable to request that SetCursorPos is added to tview ? Are there any reasons not to add this functionality?

I'm planning on replacing the InputField "engine" with that of TextArea so we get all the TextArea functionality (e.g. copy+paste, selections, etc.) in InputField also. When that is done, it is conceivable that I add a SetCursorPos method.

This can take some time though. It's quite possible that one of the forks will have this before this repo does.

<!-- gh-comment-id:1740786049 --> @rivo commented on GitHub (Sep 29, 2023): > would it be unreasonable to request that `SetCursorPos` is added to `tview` ? Are there any reasons not to add this functionality? I'm planning on replacing the `InputField` "engine" with that of `TextArea` so we get all the `TextArea` functionality (e.g. copy+paste, selections, etc.) in `InputField` also. When that is done, it is conceivable that I add a `SetCursorPos` method. This can take some time though. It's quite possible that one of the forks will have this before this repo does.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#650
No description provided.