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

Panic in MouseHandler for TextView with borders #959

Closed
Macmod opened this issue Mar 14, 2024 · 2 comments
Closed

Panic in MouseHandler for TextView with borders #959

Macmod opened this issue Mar 14, 2024 · 2 comments

Comments

@Macmod
Copy link
Contributor

Macmod commented Mar 14, 2024

It seems that https://github.com/rivo/tview/blob/master/textview.go#L1386 is missing a bounds check for when y+t.lineOffset is negative, which leads to a panic in this scenario, when the user clicks on the top border instead of the text itself:

Sample

package main

import (
        "fmt"
        "log"

        "github.com/rivo/tview"
)

func main() {
        tabs := tview.NewTextView().SetRegions(true)
        tabs.SetBorder(true)

        fmt.Fprintf(tabs, `["%s"][white]%s[black][""] `, "0", "Anything")

        myApp := tview.NewApplication()
        myApp.EnableMouse(true)

        myFlex := tview.NewFlex().SetDirection(tview.FlexRow).
                AddItem(
                        tview.NewFlex().
                                AddItem(tabs, 20, 0, false),
                        3, 0, false,
                )

        if err := myApp.SetRoot(myFlex, true).Run(); err != nil {
                log.Fatal(err)
        }
}

Trace

panic: runtime error: index out of range [-1] [recovered]
        panic: runtime error: index out of range [-1]

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1()
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/application.go:285 +0x45
panic({0x545560?, 0xc00012e000?})
        /usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/rivo/tview.(*TextView).MouseHandler.func1(0x3, 0x18?, 0xc000116310)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/textview.go:1386 +0x32e
github.com/rivo/tview.(*TextView).MouseHandler.(*Box).WrapMouseHandler.func2(0xa000?, 0xc000100000?, 0xc000118318?)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/box.go:226 +0x58
github.com/rivo/tview.(*Flex).MouseHandler.func1(0x3347?, 0xc0001142a0, 0x18?)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/flex.go:239 +0xc3
github.com/rivo/tview.(*Flex).MouseHandler.(*Box).WrapMouseHandler.func2(0xc630?, 0x10?, 0x538760?)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/box.go:226 +0x58
github.com/rivo/tview.(*Flex).MouseHandler.func1(0x5b78?, 0xc0001142a0, 0x10?)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/flex.go:239 +0xc3
github.com/rivo/tview.(*Flex).MouseHandler.(*Box).WrapMouseHandler.func2(0xc600?, 0x43798e?, 0x1?)        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/box.go:226 +0x58
github.com/rivo/tview.(*Application).fireMouseActions.func1(0x6500?)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/application.go:522 +0x182
github.com/rivo/tview.(*Application).fireMouseActions(0xc00018e000, 0xc0001142a0)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/application.go:559 +0x2c9
github.com/rivo/tview.(*Application).Run(0xc00018e000)
        /home/macmod/go/pkg/mod/github.com/rivo/tview@v0.0.0-20240307173318-e804876934a1/application.go:458 +0xbc5
main.main()
        /home/macmod/Code/tview-issue/test.go:26 +0x397
@digitallyserviced
Copy link
Contributor

@Macmod
#963

You should be able to pull/go mod edit -replace my PR's branch, or you can wait for @rivo to merge PR... however, he may be a while.

Here's another reply I made with details about using a diff branch if you dont want to wait for @rivo in your project

rivo added a commit that referenced this issue Apr 3, 2024
fixing #959 textview mouse out of bounds fix
@rivo
Copy link
Owner

rivo commented Apr 3, 2024

Fixed with #963

@rivo rivo closed this as completed Apr 3, 2024
shivaraj-bh added a commit to shivaraj-bh/process-compose that referenced this issue May 17, 2024
… v0.0.0-20240505185119-ed116790de0f

This version includes rivo/tview#959, which resolves F1bonacc1#186
kopecmaciej pushed a commit to kopecmaciej/tview that referenced this issue Aug 27, 2024
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

3 participants