@@ -20,14 +20,16 @@ const dirHeaderHeight = 3
2020
2121type Model struct {
2222 common.Common
23- vp viewport.Model
24- buffer * bytes.Buffer
25- file * gitdiff.File
23+ vp viewport.Model
24+ buffer * bytes.Buffer
25+ file * gitdiff.File
26+ sideBySide bool
2627}
2728
28- func New () Model {
29+ func New (sideBySide bool ) Model {
2930 return Model {
30- vp : viewport.Model {},
31+ vp : viewport.Model {},
32+ sideBySide : sideBySide ,
3133 }
3234}
3335
@@ -76,7 +78,7 @@ func (m *Model) SetSize(width, height int) tea.Cmd {
7678 m .Height = height
7779 m .vp .Width = m .Width
7880 m .vp .Height = m .Height - dirHeaderHeight
79- return diff (m .file , m .Width )
81+ return diff (m .file , m .Width , m . sideBySide )
8082}
8183
8284func (m Model ) headerView () string {
@@ -117,13 +119,19 @@ func (m Model) headerView() string {
117119func (m Model ) SetFilePatch (file * gitdiff.File ) (Model , tea.Cmd ) {
118120 m .buffer = new (bytes.Buffer )
119121 m .file = file
120- return m , diff (m .file , m .Width )
122+ return m , diff (m .file , m .Width , m . sideBySide )
121123}
122124
123125func (m * Model ) GoToTop () {
124126 m .vp .GotoTop ()
125127}
126128
129+ // SetSideBySide updates the diff view mode and re-renders.
130+ func (m * Model ) SetSideBySide (sideBySide bool ) tea.Cmd {
131+ m .sideBySide = sideBySide
132+ return diff (m .file , m .Width , m .sideBySide )
133+ }
134+
127135func (m * Model ) LineUp (n int ) {
128136 m .vp .LineUp (n )
129137}
@@ -142,19 +150,19 @@ func (m *Model) ScrollDown(lines int) {
142150 m .vp .LineDown (lines )
143151}
144152
145-
146- func diff (file * gitdiff.File , width int ) tea.Cmd {
153+ func diff (file * gitdiff.File , width int , sideBySidePreference bool ) tea.Cmd {
147154 if width == 0 || file == nil {
148155 return nil
149156 }
150157 return func () tea.Msg {
151- sideBySide := ! file .IsNew && ! file .IsDelete
158+ // Only use side-by-side if preference is true AND file is not new/deleted
159+ useSideBySide := sideBySidePreference && ! file .IsNew && ! file .IsDelete
152160 args := []string {
153161 "--paging=never" ,
154162 fmt .Sprintf ("-w=%d" , width ),
155163 fmt .Sprintf ("--max-line-length=%d" , width ),
156164 }
157- if sideBySide {
165+ if useSideBySide {
158166 args = append (args , "--side-by-side" )
159167 }
160168 deltac := exec .Command ("delta" , args ... )
0 commit comments