on main help sign in
fix: enable left/right scrolling of diff (#1984)
9faa8b2Kujtim Hoxha
internal/ui/dialog/permissions.go+36−7
@@ -70,6 +70,7 @@ type Permissions struct {
70 // Diff view state.
70 // Diff view state.
71 diffSplitMode *bool // nil means use default based on width
71 diffSplitMode *bool // nil means use default based on width
72 defaultDiffSplitMode bool // default split mode based on width
72 defaultDiffSplitMode bool // default split mode based on width
73+ diffXOffset int // horizontal scroll offset for diff view
73 unifiedDiffContent string
74 unifiedDiffContent string
74 splitDiffContent string
75 splitDiffContent string
75
76
@@ -259,12 +260,31 @@ func (p *Permissions) HandleMsg(msg tea.Msg) Action {
259 case key.Matches(msg, p.keyMap.ScrollUp):
260 case key.Matches(msg, p.keyMap.ScrollUp):
260 p.viewport, _ = p.viewport.Update(msg)
261 p.viewport, _ = p.viewport.Update(msg)
261 case key.Matches(msg, p.keyMap.ScrollLeft):
262 case key.Matches(msg, p.keyMap.ScrollLeft):
263+ if p.hasDiffView() {
264+ p.scrollLeft()
265+ } else {
262− p.viewport, _ = p.viewport.Update(msg)
266+ p.viewport, _ = p.viewport.Update(msg)
267+ }
263 case key.Matches(msg, p.keyMap.ScrollRight):
268 case key.Matches(msg, p.keyMap.ScrollRight):
269+ if p.hasDiffView() {
270+ p.scrollRight()
271+ } else {
264− p.viewport, _ = p.viewport.Update(msg)
272+ p.viewport, _ = p.viewport.Update(msg)
273+ }
265 }
274 }
266 case tea.MouseWheelMsg:
275 case tea.MouseWheelMsg:
276+ if p.hasDiffView() {
277+ switch msg.Button {
278+ case tea.MouseWheelLeft:
279+ p.scrollLeft()
280+ case tea.MouseWheelRight:
281+ p.scrollRight()
282+ default:
267− p.viewport, _ = p.viewport.Update(msg)
283+ p.viewport, _ = p.viewport.Update(msg)
284+ }
285+ } else {
286+ p.viewport, _ = p.viewport.Update(msg)
287+ }
268 default:
288 default:
269 // Pass unhandled keys to viewport for non-diff content scrolling.
289 // Pass unhandled keys to viewport for non-diff content scrolling.
270 if !p.hasDiffView() {
290 if !p.hasDiffView() {
@@ -309,6 +329,18 @@ func (p *Permissions) isSplitMode() bool {
309 return p.defaultDiffSplitMode
329 return p.defaultDiffSplitMode
310}
330}
311
331
332+const horizontalScrollStep = 5
333+
334+func (p *Permissions) scrollLeft() {
335+ p.diffXOffset = max(0, p.diffXOffset-horizontalScrollStep)
336+ p.viewportDirty = true
337+}
338+
339+func (p *Permissions) scrollRight() {
340+ p.diffXOffset += horizontalScrollStep
341+ p.viewportDirty = true
342+}
343+
312// Draw implements [Dialog].
344// Draw implements [Dialog].
313func (p *Permissions) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
345func (p *Permissions) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
314 t := p.com.Styles
346 t := p.com.Styles
@@ -558,10 +590,7 @@ func (p *Permissions) renderDiff(filePath, oldContent, newContent string, conten
558 formatter := common.DiffFormatter(p.com.Styles).
590 formatter := common.DiffFormatter(p.com.Styles).
559 Before(fsext.PrettyPath(filePath), oldContent).
591 Before(fsext.PrettyPath(filePath), oldContent).
560 After(fsext.PrettyPath(filePath), newContent).
592 After(fsext.PrettyPath(filePath), newContent).
561− // TODO: Allow horizontal scrolling instead of cropping. However, the
593+ XOffset(p.diffXOffset).
562− // diffview currently would only background color the width of the
563− // content. If the viewport is wider than the content, the rest of the
564− // line would not be colored properly.
565 Width(contentWidth)
594 Width(contentWidth)
566
595
567 var result string
596 var result string
internal/ui/model/sidebar.go+1−2
@@ -51,9 +51,8 @@ func (m *UI) modelInfo(width int) string {
51 Cost: m.session.Cost,
51 Cost: m.session.Cost,
52 ModelContext: model.CatwalkCfg.ContextWindow,
52 ModelContext: model.CatwalkCfg.ContextWindow,
53 }
53 }
54− return common.ModelInfo(m.com.Styles, model.CatwalkCfg.Name, providerName, reasoningInfo, modelContext, width)
55 }
54 }
56− return ""
55+ return common.ModelInfo(m.com.Styles, model.CatwalkCfg.Name, providerName, reasoningInfo, modelContext, width)
57}
56}
58
57
59// getDynamicHeightLimits will give us the num of items to show in each section based on the hight
58// getDynamicHeightLimits will give us the num of items to show in each section based on the hight