@@ -7,16 +7,17 @@ package tui
77import  (
88	"github.com/charmbracelet/bubbles/key" 
99	"github.com/charmbracelet/bubbles/textinput" 
10+ 	"github.com/charmbracelet/bubbles/viewport" 
1011	tea "github.com/charmbracelet/bubbletea" 
1112)
1213
1314// handleMouse handles all mouse interaction. 
1415func  (m  * model ) handleMouse (msg  tea.MouseMsg ) {
1516	switch  msg .Type  {
1617	case  tea .MouseWheelUp :
17- 		m .list . CursorUp ()
18+ 		m .viewport . ViewUp ()
1819	case  tea .MouseWheelDown :
19- 		m .list . CursorDown ()
20+ 		m .viewport . ViewDown ()
2021	}
2122}
2223
@@ -63,7 +64,6 @@ func (m *model) handleKeys(msg tea.KeyMsg) tea.Cmd {
6364			m .textinput .Blur ()
6465			m .textinput .Reset ()
6566			m .state  =  defaultState 
66- 			m .stateDesc  =  "" 
6767		default :
6868			m .textinput , cmd  =  m .textinput .Update (msg )
6969			cmds  =  append (cmds , cmd )
@@ -82,7 +82,15 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8282	switch  msg  :=  msg .(type ) {
8383	case  tea.WindowSizeMsg :
8484		topGap , rightGap , bottomGap , leftGap  :=  appStyle .GetPadding ()
85- 		m .list .SetSize (msg .Width - leftGap - rightGap , msg .Height - topGap - bottomGap - 1 )
85+ 		m .width  =  msg .Width  -  leftGap  -  rightGap 
86+ 		m .height  =  msg .Height  -  topGap  -  bottomGap 
87+ 
88+ 		listWidth  :=  int (listProportion  *  float64 (m .width ))
89+ 		m .list .SetSize (listWidth , m .height - statusBarHeight )
90+ 
91+ 		viewportWidth  :=  m .width  -  listWidth 
92+ 		viewportBorderLeft  :=  viewportStyle .GetBorderLeftSize ()
93+ 		m .viewport  =  viewport .New (viewportWidth - viewportBorderLeft , m .height - statusBarHeight )
8694	case  scanMsg :
8795		m .list .SetItems (msg .items )
8896	case  tea.MouseMsg :
@@ -96,6 +104,9 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
96104
97105		m .textinput , cmd  =  m .textinput .Update (msg )
98106		cmds  =  append (cmds , cmd )
107+ 
108+ 		m .viewport , cmd  =  m .viewport .Update (msg )
109+ 		cmds  =  append (cmds , cmd )
99110	}
100111
101112	return  m , tea .Batch (cmds ... )
0 commit comments