cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / e2e / mouse_test.go
mouse_test.go 3.1K
1package e2e23import (4 "strings"5 "testing"67 ghostty "go.mitchellh.com/libghostty"8)910// leftClick presses and releases the left button at a screen cell, with11// modifiers.12func (s *session) leftClick(col, row int, mods ghostty.Mods) {13 s.mouse(ghostty.MouseActionPress, ghostty.MouseButtonLeft, col, row, mods)14 s.mouse(ghostty.MouseActionRelease, ghostty.MouseButtonLeft, col, row, mods)15}1617// drag presses at one cell, moves through the path and releases at the end.18func (s *session) drag(path ...[2]int) {19 first, last := path[0], path[len(path)-1]20 s.mouse(ghostty.MouseActionPress, ghostty.MouseButtonLeft, first[0], first[1], 0)21 for _, p := range path[1:] {22 s.mouse(ghostty.MouseActionMotion, ghostty.MouseButtonLeft, p[0], p[1], 0)23 }24 s.mouse(ghostty.MouseActionRelease, ghostty.MouseButtonLeft, last[0], last[1], 0)25}2627// wheel scrolls at a cell; up is button 4, down is button 5.28func (s *session) wheel(col, row, clicks int) {29 button := ghostty.MouseButtonFive30 if clicks < 0 {31 button, clicks = ghostty.MouseButtonFour, -clicks32 }33 for range clicks {34 s.mouse(ghostty.MouseActionPress, button, col, row, 0)35 }36}3738// Screen x of a cell in column c with default widths and no scrolling.39func colX(c int) int { return 6 + c*10 + 2 }4041func TestMouseClickDragAndShiftClick(t *testing.T) {42 t.Parallel()43 s := start(t, "")44 s.leftClick(colX(1), gridRow1+2, 0)45 s.waitForName("B3")46 s.drag([2]int{colX(0), gridRow1}, [2]int{colX(1), gridRow1 + 1}, [2]int{colX(2), gridRow1 + 2})47 s.eventually("drag selection", func() bool { return strings.Contains(s.line(29), "A1:C3") })48 s.leftClick(colX(3), gridRow1+4, ghostty.ModShift)49 s.eventually("shift+click extends", func() bool { return strings.Contains(s.line(29), "A1:D5") })5051 // The app asked the terminal to pass Shift+click through.52 s.mu.Lock()53 raw := string(s.raw)54 s.mu.Unlock()55 if !strings.Contains(raw, "\x1b[>1s") {56 t.Error("XTSHIFTESCAPE not requested")57 }58}5960func TestMouseClickWhileTypingAndFormulaReference(t *testing.T) {61 t.Parallel()62 s := start(t, "")63 s.keys("40", "<enter>", "2", "<enter>", "=")64 s.leftClick(colX(0), gridRow1, 0)65 s.waitForEntry("=A1")66 s.keys("+")67 s.leftClick(colX(0), gridRow1+1, 0)68 s.waitForEntry("=A1+A2")69 s.keys("<enter>")70 s.waitForLine(gridRow1+2, numRow(3, "42"))7172 // Clicking another cell while typing plain text accepts it there.73 s.keys("note")74 s.leftClick(colX(2), gridRow1, 0)75 s.waitForName("C1")76 s.waitForLine(gridRow1+3, " 4 note")77}7879func TestMouseResizeAndWheel(t *testing.T) {80 t.Parallel()81 s := start(t, "")82 border := 6 + 10 - 183 s.drag([2]int{border, 3}, [2]int{border + 4, 3}, [2]int{border + 8, 3})84 s.eventually("column A wider", func() bool {85 return strings.HasPrefix(s.line(3), strings.Repeat(" ", 6)+strings.Repeat(" ", 8)+"A")86 })87 s.wheel(colX(2), gridRow1+5, 4)88 s.waitForLine(gridRow1, " 13")89 // The active cell didn't move; arrowing to A2 scrolls just enough to90 // show it again.91 s.keys("<down>")92 s.waitForLine(gridRow1, " 2")93}9495func TestMouseDoubleClickEdits(t *testing.T) {96 t.Parallel()97 s := start(t, "")98 s.keys("hello", "<enter>")99 s.leftClick(colX(0), gridRow1, 0)100 s.leftClick(colX(0), gridRow1, 0)101 s.waitFor("EDIT")102 s.waitForEntry("hello")103}