@@ -97,19 +97,30 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
9797 return m , tea .Batch (cmds ... )
9898}
9999
100+ const scrollbarWidth = 3 // 1 space + 1 scrollbar character + 1 padding
101+
100102func (m Model ) View () string {
101- return lipgloss .JoinVertical (lipgloss .Left , m .headerView (), m .vp .View ())
103+ vpView := m .vp .View ()
104+ scrollbar := common .RenderScrollbar (m .vp .Height (), m .vp .TotalLineCount (), m .vp .YOffset ())
105+ if scrollbar != "" {
106+ vpView = lipgloss .JoinHorizontal (lipgloss .Top , vpView , " " , scrollbar )
107+ }
108+ return lipgloss .JoinVertical (lipgloss .Left , m .headerView (), vpView )
102109}
103110
104111func (m * Model ) SetSize (width , height int ) tea.Cmd {
105112 m .Width = width
106113 m .Height = height
107- m .vp .SetWidth (m .Width )
114+ m .vp .SetWidth (m .contentWidth () )
108115 m .vp .SetHeight (m .Height - dirHeaderHeight )
109116 m .cache = make (nodeCache )
110117 return m .diff ()
111118}
112119
120+ func (m Model ) contentWidth () int {
121+ return m .Width - scrollbarWidth
122+ }
123+
113124func (m * Model ) diff () tea.Cmd {
114125 if m .file != nil {
115126 key := cacheKey (m .file .path , m .sideBySide )
@@ -126,7 +137,7 @@ func (m *Model) diff() tea.Cmd {
126137 }
127138 m .file = node
128139 m .cache [key ] = node
129- return diffFile (node , m .Width , m .sideBySide )
140+ return diffFile (node , m .contentWidth () , m .sideBySide )
130141 } else if m .dir != nil {
131142 key := cacheKey (m .dir .path , m .sideBySide )
132143 if cached , ok := m .cache [key ]; ok && cached .diff != "" {
@@ -146,7 +157,7 @@ func (m *Model) diff() tea.Cmd {
146157 if m .dir .path == "/" {
147158 preamble = m .preamble
148159 }
149- return diffDir (node , m .Width , m .sideBySide , preamble )
160+ return diffDir (node , m .contentWidth () , m .sideBySide , preamble )
150161 }
151162
152163 return nil
@@ -217,7 +228,7 @@ func (m Model) SetFilePatch(file *gitdiff.File) (Model, tea.Cmd) {
217228 }
218229 m .cache [key ] = m .file
219230
220- return m , diffFile (m .file , m .Width , m .sideBySide )
231+ return m , diffFile (m .file , m .contentWidth () , m .sideBySide )
221232}
222233
223234func (m Model ) SetDirPatch (dirPath string , files []* gitdiff.File ) (Model , tea.Cmd ) {
@@ -247,7 +258,7 @@ func (m Model) SetDirPatch(dirPath string, files []*gitdiff.File) (Model, tea.Cm
247258 if dirPath == "/" {
248259 preamble = m .preamble
249260 }
250- return m , diffDir (m .dir , m .Width , m .sideBySide , preamble )
261+ return m , diffDir (m .dir , m .contentWidth () , m .sideBySide , preamble )
251262}
252263
253264func (m * Model ) GoToTop () {
0 commit comments