Skip to content

Commit

Permalink
Ensure we request focus on desktop when tapped
Browse files Browse the repository at this point in the history
Fixes #80
  • Loading branch information
andydotxyz committed May 15, 2024
1 parent 6a6996b commit f85b3bf
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (t *Terminal) MinSize() fyne.Size {

// MouseDown handles the down action for desktop mouse events.
func (t *Terminal) MouseDown(ev *desktop.MouseEvent) {
t.requestFocus()
if t.hasSelectedText() {
t.clearSelectedText()
}
Expand Down Expand Up @@ -209,8 +210,8 @@ func (t *Terminal) SetStartDir(path string) {
}

// Tapped makes sure we ask for focus if user taps us.
func (t *Terminal) Tapped(ev *fyne.PointEvent) {
fyne.CurrentApp().Driver().CanvasForObject(t).Focus(t)
func (t *Terminal) Tapped(*fyne.PointEvent) {
t.requestFocus()
}

// Text returns the contents of the buffer as a single string joined with `\n` (no style information).
Expand Down Expand Up @@ -300,6 +301,12 @@ func (t *Terminal) guessCellSize() fyne.Size {
return fyne.NewSize(float32(math.Round(float64(min.Width))), float32(math.Round(float64(min.Height))))
}

func (t *Terminal) requestFocus() {
if c := fyne.CurrentApp().Driver().CanvasForObject(t); c != nil {
c.Focus(t)
}
}

func (t *Terminal) run() {
buf := make([]byte, bufLen)
var leftOver []byte
Expand Down

0 comments on commit f85b3bf

Please sign in to comment.