Skip to content

Commit

Permalink
fix: ignore mouse events when modal is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Feb 3, 2023
1 parent 10c8ae1 commit 8bdce9a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tui/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ func (ui *UI) onMouse(event *tcell.EventMouse, action tview.MouseAction) (*tcell
return nil, action
}

if ui.pages.HasPage("confirm") ||
ui.pages.HasPage("progress") ||
ui.pages.HasPage("deleting") ||
ui.pages.HasPage("emptying") ||
ui.pages.HasPage("help") {
return nil, action
}

switch action {
case tview.MouseLeftDoubleClick:
row, column := ui.table.GetSelection()
Expand Down
26 changes: 26 additions & 0 deletions tui/mouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ func TestScroll(t *testing.T) {
assert.Equal(t, row, 0)
}

func TestScrollWhenPageOpened(t *testing.T) {
simScreen := testapp.CreateSimScreen(50, 50)
defer simScreen.Fini()

app := testapp.CreateMockedApp(true)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, true, true, false, false, false)
ui.Analyzer = &testanalyze.MockedAnalyzer{}
ui.done = make(chan struct{})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)

<-ui.done // wait for analyzer

for _, f := range ui.app.(*testapp.MockedApp).GetUpdateDraws() {
f()
}

// open confirm dialog
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'd', 0))

ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseScrollDown)
row, _ := ui.table.GetSelection()
// scrolling does nothing
assert.Equal(t, 0, row)
}

func TestEmptyEvent(t *testing.T) {
simScreen := testapp.CreateSimScreen(50, 50)
defer simScreen.Fini()
Expand Down

0 comments on commit 8bdce9a

Please sign in to comment.