[GH-ISSUE #958] Bug in TextArea Select #704

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

Originally created by @eeeXun on GitHub (Mar 12, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/958

Given the following code, you can press C-q to see the selection range. I want to select all text, so textArea.Select(0, len(textArea.GetText()))

package main

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

func main() {
	app := tview.NewApplication()

	textArea := tview.NewTextArea().
		SetPlaceholder("Enter text here...").
		SetSelectedStyle(tcell.StyleDefault.Background(tcell.ColorYellow).Foreground(tcell.ColorRed))
	textArea.SetTitle("Text Area").SetBorder(true)

	textArea.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		if event.Key() == tcell.KeyCtrlQ {
			textArea.Select(0, len(textArea.GetText()))
			return nil
		}
		return event
	})

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

image

The bug is when your text is too long to fit on a line in terminal.
image

This could not be solved even I increase the value of second parameter in Select. textArea.Select(0, 10000)

Originally created by @eeeXun on GitHub (Mar 12, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/958 Given the following code, you can press `C-q` to see the selection range. I want to select all text, so `textArea.Select(0, len(textArea.GetText()))` ```go package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textArea := tview.NewTextArea(). SetPlaceholder("Enter text here..."). SetSelectedStyle(tcell.StyleDefault.Background(tcell.ColorYellow).Foreground(tcell.ColorRed)) textArea.SetTitle("Text Area").SetBorder(true) textArea.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyCtrlQ { textArea.Select(0, len(textArea.GetText())) return nil } return event }) if err := app.SetRoot(textArea, true).EnableMouse(true).Run(); err != nil { panic(err) } } ``` ![image](https://github.com/rivo/tview/assets/58657914/4e3ac62f-15e1-4f57-be9a-25cf6727072d) The bug is when your text is too long to fit on a line in terminal. ![image](https://github.com/rivo/tview/assets/58657914/f395aaa7-326b-468f-bfa3-320c43af3dbc) This could not be solved even I increase the value of second parameter in `Select`. `textArea.Select(0, 10000)`
kerem closed this issue 2026-03-04 01:07:09 +03:00
Author
Owner

@naviji commented on GitHub (Mar 31, 2024):

I'm able to reproduce this. I'll see if I can fix it.

<!-- gh-comment-id:2028874643 --> @naviji commented on GitHub (Mar 31, 2024): I'm able to reproduce this. I'll see if I can fix it.
Author
Owner

@naviji commented on GitHub (Apr 1, 2024):

I see that the Ctrl-L key can also be used to select the entire text.

For some reason selecting via Ctrl-L doesn't seem to trigger the selection issue. Does that help you?

<!-- gh-comment-id:2029632434 --> @naviji commented on GitHub (Apr 1, 2024): I see that the Ctrl-L key can also be used to select the entire text. For some reason selecting via Ctrl-L doesn't seem to trigger the selection issue. Does that help you?
Author
Owner

@eeeXun commented on GitHub (Apr 1, 2024):

@naviji Hi, thanks for your help.
Actually, my problem is I want to use TextArea.Replace instead of TextArea.SetText to reserve the undo history. (I want to clear the text, textArea.Replace(0, len(textArea.GetText()), "") )

When I call TextArea.Replace, it produces the similar problem as mentioned above. So I trace the code and find this function calls TextArea.Select.

That's why I report the bug in TextArea.Select

<!-- gh-comment-id:2029644780 --> @eeeXun commented on GitHub (Apr 1, 2024): @naviji Hi, thanks for your help. Actually, my problem is I want to use `TextArea.Replace` instead of `TextArea.SetText` to reserve the undo history. (I want to clear the text, `textArea.Replace(0, len(textArea.GetText()), "") `) When I call `TextArea.Replace`, it produces the similar problem as mentioned above. So I trace the code and find this function calls `TextArea.Select`. That's why I report the bug in `TextArea.Select`
Author
Owner

@rivo commented on GitHub (Apr 2, 2024):

Hi everyone, thanks for reporting this bug. The latest commit should fix this.

<!-- gh-comment-id:2033014850 --> @rivo commented on GitHub (Apr 2, 2024): Hi everyone, thanks for reporting this bug. The latest commit should fix this.
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#704
No description provided.