[GH-ISSUE #988] Bug in TextArea Select when cursor is on a new line #717

Closed
opened 2026-03-04 01:07:14 +03:00 by kerem · 1 comment
Owner

Originally created by @eeeXun on GitHub (May 18, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/988

I've already reported a similar bug in #958. So I use the same code to demonstrate. (Press C-q to select text)

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)
	}
}

The bug introduced when the cursor is on a new line and you can not select any words.

image

Originally created by @eeeXun on GitHub (May 18, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/988 I've already reported a similar bug in #958. So I use the same code to demonstrate. (Press `C-q` to select text) ```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) } } ``` The bug introduced when the cursor is on a new line and you can not select any words. ![image](https://github.com/rivo/tview/assets/58657914/9c3f63d4-f3a3-4855-983e-e3c400ce98a3)
kerem closed this issue 2026-03-04 01:07:14 +03:00
Author
Owner

@rivo commented on GitHub (May 19, 2024):

Thanks for reporting this. These edge cases are difficult to spot but the latest commit should fix this.

<!-- gh-comment-id:2119142544 --> @rivo commented on GitHub (May 19, 2024): Thanks for reporting this. These edge cases are difficult to spot but 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#717
No description provided.