feat(diffview): only process scroll events when pointer is over dialog

Andrey Nering created

Change summary

internal/tui/components/dialogs/permissions/permissions.go | 23 +++++++
internal/tui/tui.go                                        |  5 -
2 files changed, 23 insertions(+), 5 deletions(-)

Detailed changes

internal/tui/components/dialogs/permissions/permissions.go 🔗

@@ -64,6 +64,8 @@ type permissionDialogCmp struct {
 	positionRow int // Row position for dialog
 	positionCol int // Column position for dialog
 
+	finalDialogHeight int
+
 	keyMap KeyMap
 }
 
@@ -159,7 +161,7 @@ func (p *permissionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			cmds = append(cmds, cmd)
 		}
 	case tea.MouseWheelMsg:
-		if p.supportsDiffView() {
+		if p.supportsDiffView() && p.isMouseOverDialog(msg.Mouse().X, msg.Mouse().Y) {
 			switch msg.Button {
 			case tea.MouseWheelDown:
 				p.scrollDown()
@@ -196,6 +198,21 @@ func (p *permissionDialogCmp) scrollRight() {
 	p.contentDirty = true
 }
 
+// isMouseOverDialog checks if the given mouse coordinates are within the dialog bounds.
+// Returns true if the mouse is over the dialog area, false otherwise.
+func (p *permissionDialogCmp) isMouseOverDialog(x, y int) bool {
+	if p.permission.ID == "" {
+		return false
+	}
+	var (
+		dialogX      = p.positionCol
+		dialogY      = p.positionRow
+		dialogWidth  = p.width
+		dialogHeight = p.finalDialogHeight
+	)
+	return x >= dialogX && x < dialogX+dialogWidth && y >= dialogY && y < dialogY+dialogHeight
+}
+
 func (p *permissionDialogCmp) selectCurrentOption() tea.Cmd {
 	var action PermissionAction
 
@@ -683,7 +700,7 @@ func (p *permissionDialogCmp) render() string {
 	}
 	content := lipgloss.JoinVertical(lipgloss.Top, strs...)
 
-	return baseStyle.
+	dialog := baseStyle.
 		Padding(0, 1).
 		Border(lipgloss.RoundedBorder()).
 		BorderForeground(t.BorderFocus).
@@ -691,6 +708,8 @@ func (p *permissionDialogCmp) render() string {
 		Render(
 			content,
 		)
+	p.finalDialogHeight = lipgloss.Height(dialog)
+	return dialog
 }
 
 func (p *permissionDialogCmp) View() string {

internal/tui/tui.go 🔗

@@ -264,12 +264,11 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		return a, a.handleKeyPressMsg(msg)
 
 	case tea.MouseWheelMsg:
-		if a.dialog.HasDialogs() && a.dialog.ActiveDialogID() == permissions.PermissionsDialogID {
+		if a.dialog.HasDialogs() {
 			u, dialogCmd := a.dialog.Update(msg)
 			a.dialog = u.(dialogs.DialogCmp)
 			cmds = append(cmds, dialogCmd)
-		}
-		if !a.dialog.HasDialogs() {
+		} else {
 			updated, pageCmd := a.pages[a.currentPage].Update(msg)
 			a.pages[a.currentPage] = updated.(util.Model)
 			cmds = append(cmds, pageCmd)