Skip to content

Commit

Permalink
fix(ansi): add mouse release with modifiers test
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Dec 10, 2024
1 parent e41b682 commit f4f373c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ansi/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (b MouseButton) String() string {
//
// - The eighth bit indicates additional buttons.
//
// If button is [MouseRelease], and motion is false, this returns a release
// event. If button is undefined, this function returns 0xff.
// If button is [MouseNone], and motion is false, this returns a release event.
// If button is undefined, this function returns 0xff.
func (b MouseButton) Button(motion, shift, alt, ctrl bool) (m byte) {
// mouse bit shifts
const (
Expand All @@ -98,7 +98,7 @@ func (b MouseButton) Button(motion, shift, alt, ctrl bool) (m byte) {
bitsMask = 0b0000_0011
)

if b == MouseRelease {
if b == MouseNone {
m = bitsMask
} else if b >= MouseLeft && b <= MouseRight {
m = byte(b - MouseLeft)
Expand Down
10 changes: 8 additions & 2 deletions ansi/mouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ func TestMouseButton(t *testing.T) {
cases := []test{
{
name: "mouse release",
btn: MouseRelease,
btn: MouseNone,
want: 0b0000_0011,
},
{
name: "mouse release with ctrl",
btn: MouseNone,
ctrl: true,
want: 0b0001_0011,
},
{
name: "mouse left",
btn: MouseLeft,
Expand Down Expand Up @@ -177,7 +183,7 @@ func TestMouseSgr(t *testing.T) {
},
{
name: "mouse release",
btn: MouseRelease.Button(false, false, false, false),
btn: MouseNone.Button(false, false, false, false),
x: 5,
y: 5,
release: true,
Expand Down

0 comments on commit f4f373c

Please sign in to comment.