[GH-ISSUE #1122] [Feature Request]: Methods to move the cursor to start/end in TextArea #812

Closed
opened 2026-03-04 01:07:55 +03:00 by kerem · 2 comments
Owner

Originally created by @dbohdan on GitHub (Sep 21, 2025).
Original GitHub issue: https://github.com/rivo/tview/issues/1122

I am looking to migrate my application from Bubble Tea to tview for its better text area performance with larger buffers (noticeable at hundreds of lines). Most functionality has a clear replacement, but moving the cursor to the start or end of the buffer doesn't seem to.

It would be useful to have methods like textArea.MoveCursorToStart() and textArea.MoveCursorToEnd() to do this directly. I have only found a way to emulate it with textArea.SetText(textArea.GetText(), false) and textArea.SetText(textArea.GetText(), true).

If you make a breaking change in the future, consider also binding these operations to the semi-standard shortcuts Ctrl+Home (start) and Ctrl+End (end).

Originally created by @dbohdan on GitHub (Sep 21, 2025). Original GitHub issue: https://github.com/rivo/tview/issues/1122 I am looking to migrate [my application](https://github.com/dbohdan/pago) from Bubble Tea to tview for its better text area performance with larger buffers (noticeable at hundreds of lines). Most functionality has a clear replacement, but moving the cursor to the start or end of the buffer doesn't seem to. It would be useful to have methods like `textArea.MoveCursorToStart()` and `textArea.MoveCursorToEnd()` to do this directly. I have only found a way to emulate it with `textArea.SetText(textArea.GetText(), false)` and `textArea.SetText(textArea.GetText(), true)`. If you make a breaking change in the future, consider also binding these operations to the semi-standard shortcuts Ctrl+Home (start) and Ctrl+End (end).
kerem closed this issue 2026-03-04 01:07:55 +03:00
Author
Owner

@rivo commented on GitHub (Sep 27, 2025):

Maybe somewhat unintuitively, this is already possible with the Select() function.

To move to the beginning of the text:

textArea.Select(0, 0)

To move to the end of the text:

length := textArea.GetTextLength()
textArea.Select(length, length)

I think the reason I did not introduce Ctrl-Home / Ctrl-End to tview was that on my Mac, this is not handed to the terminal application but instead repositions and resizes the terminal window (Ctrl-Home being Ctrl-Fn-LeftArrow). It should be quite simple to add this to your application, however.

<!-- gh-comment-id:3341644701 --> @rivo commented on GitHub (Sep 27, 2025): Maybe somewhat unintuitively, this is already possible with the [`Select()`](https://pkg.go.dev/github.com/rivo/tview#TextArea.Select) function. To move to the beginning of the text: ```go textArea.Select(0, 0) ``` To move to the end of the text: ```go length := textArea.GetTextLength() textArea.Select(length, length) ``` I think the reason I did not introduce <kbd>Ctrl-Home</kbd> / <kbd>Ctrl-End</kbd> to `tview` was that on my Mac, this is not handed to the terminal application but instead repositions and resizes the terminal window (<kbd>Ctrl-Home</kbd> being <kbd>Ctrl-Fn-LeftArrow</kbd>). It should be quite simple to add this to your application, however.
Author
Owner

@dbohdan commented on GitHub (Sep 27, 2025):

Oh, I see. Thanks for explaining. I have implemented the shortcuts in my app.

Implementation.
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
	switch event.Key() {
	// ...
	case tcell.KeyHome:
		if event.Modifiers()&tcell.ModCtrl != 0 {
			textArea.Select(0, 0)
			return nil
		}

	case tcell.KeyEnd:
		if event.Modifiers()&tcell.ModCtrl != 0 {
			length := textArea.GetTextLength()
			textArea.Select(length, length)
			return nil
		}
	}

	return event
})

I didn't notice this line in the documentation for Select:

They may be the same, in which case the cursor is placed at the given position.

I think I searched for "cursor" and missed it when going through the matches because there were too many, then focused on looking for "move", "beginning", "start", and "end".

TextArea probably doesn't need additional methods, but I think it's a good idea to document cursor manipulation some more. One way to do it would be by implementing Ctrl+Home and Ctrl+End in demos/textarea/.

P.S.: The migration from Bubble Tea to tview has been successfully completed.

<!-- gh-comment-id:3341738632 --> @dbohdan commented on GitHub (Sep 27, 2025): Oh, I see. Thanks for explaining. I have implemented the shortcuts in my app. <details> <summary>Implementation.</summary> ```go app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Key() { // ... case tcell.KeyHome: if event.Modifiers()&tcell.ModCtrl != 0 { textArea.Select(0, 0) return nil } case tcell.KeyEnd: if event.Modifiers()&tcell.ModCtrl != 0 { length := textArea.GetTextLength() textArea.Select(length, length) return nil } } return event }) ``` </details> I didn't notice this line in the documentation for `Select`: > They may be the same, in which case the cursor is placed at the given position. I think I searched for "cursor" and missed it when going through the matches because there were too many, then focused on looking for "move", "beginning", "start", and "end". `TextArea` probably doesn't need additional methods, but I think it's a good idea to document cursor manipulation some more. One way to do it would be by implementing Ctrl+Home and Ctrl+End in `demos/textarea/`. P.S.: The migration from Bubble Tea to tview has been successfully completed.
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#812
No description provided.