on main help sign in
feat(diffview): add support for mouse scrolling
2917109Andrey Nering
internal/tui/components/dialogs/permissions/permissions.go+37−8
@@ -134,26 +134,22 @@ func (p *permissionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
134 }
134 }
135 case key.Matches(msg, p.keyMap.ScrollDown):
135 case key.Matches(msg, p.keyMap.ScrollDown):
136 if p.supportsDiffView() {
136 if p.supportsDiffView() {
137− p.diffYOffset += 1
137+ p.scrollDown()
138− p.contentDirty = true // Mark content as dirty when scrolling
139 return p, nil
138 return p, nil
140 }
139 }
141 case key.Matches(msg, p.keyMap.ScrollUp):
140 case key.Matches(msg, p.keyMap.ScrollUp):
142 if p.supportsDiffView() {
141 if p.supportsDiffView() {
143− p.diffYOffset = max(0, p.diffYOffset-1)
142+ p.scrollUp()
144− p.contentDirty = true // Mark content as dirty when scrolling
145 return p, nil
143 return p, nil
146 }
144 }
147 case key.Matches(msg, p.keyMap.ScrollLeft):
145 case key.Matches(msg, p.keyMap.ScrollLeft):
148 if p.supportsDiffView() {
146 if p.supportsDiffView() {
149− p.diffXOffset = max(0, p.diffXOffset-5)
147+ p.scrollLeft()
150− p.contentDirty = true // Mark content as dirty when scrolling
151 return p, nil
148 return p, nil
152 }
149 }
153 case key.Matches(msg, p.keyMap.ScrollRight):
150 case key.Matches(msg, p.keyMap.ScrollRight):
154 if p.supportsDiffView() {
151 if p.supportsDiffView() {
155− p.diffXOffset += 5
152+ p.scrollRight()
156− p.contentDirty = true // Mark content as dirty when scrolling
157 return p, nil
153 return p, nil
158 }
154 }
159 default:
155 default:
@@ -162,11 +158,44 @@ func (p *permissionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
162 p.contentViewPort = viewPort
158 p.contentViewPort = viewPort
163 cmds = append(cmds, cmd)
159 cmds = append(cmds, cmd)
164 }
160 }
161+ case tea.MouseWheelMsg:
162+ if p.supportsDiffView() {
163+ switch msg.Button {
164+ case tea.MouseWheelDown:
165+ p.scrollDown()
166+ case tea.MouseWheelUp:
167+ p.scrollUp()
168+ case tea.MouseWheelLeft:
169+ p.scrollLeft()
170+ case tea.MouseWheelRight:
171+ p.scrollRight()
172+ }
173+ }
165 }
174 }
166
175
167 return p, tea.Batch(cmds...)
176 return p, tea.Batch(cmds...)
168}
177}
169
178
179+func (p *permissionDialogCmp) scrollDown() {
180+ p.diffYOffset += 1
181+ p.contentDirty = true
182+}
183+
184+func (p *permissionDialogCmp) scrollUp() {
185+ p.diffYOffset = max(0, p.diffYOffset-1)
186+ p.contentDirty = true
187+}
188+
189+func (p *permissionDialogCmp) scrollLeft() {
190+ p.diffXOffset = max(0, p.diffXOffset-5)
191+ p.contentDirty = true
192+}
193+
194+func (p *permissionDialogCmp) scrollRight() {
195+ p.diffXOffset += 5
196+ p.contentDirty = true
197+}
198+
170func (p *permissionDialogCmp) selectCurrentOption() tea.Cmd {
199func (p *permissionDialogCmp) selectCurrentOption() tea.Cmd {
171 var action PermissionAction
200 var action PermissionAction
172
201
internal/tui/tui.go+5
@@ -264,6 +264,11 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
264 return a, a.handleKeyPressMsg(msg)
264 return a, a.handleKeyPressMsg(msg)
265
265
266 case tea.MouseWheelMsg:
266 case tea.MouseWheelMsg:
267+ if a.dialog.HasDialogs() && a.dialog.ActiveDialogID() == permissions.PermissionsDialogID {
268+ u, dialogCmd := a.dialog.Update(msg)
269+ a.dialog = u.(dialogs.DialogCmp)
270+ cmds = append(cmds, dialogCmd)
271+ }
267 if !a.dialog.HasDialogs() {
272 if !a.dialog.HasDialogs() {
268 updated, pageCmd := a.pages[a.currentPage].Update(msg)
273 updated, pageCmd := a.pages[a.currentPage].Update(msg)
269 a.pages[a.currentPage] = updated.(util.Model)
274 a.pages[a.currentPage] = updated.(util.Model)