mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
wip: add scrolling
This commit is contained in:
+24
-26
@@ -377,39 +377,37 @@ func (m *Model) SetCursor(n int) {
|
|||||||
// MoveUp moves the selection up by any number of rows.
|
// MoveUp moves the selection up by any number of rows.
|
||||||
// It can not go above the first row.
|
// It can not go above the first row.
|
||||||
func (m *Model) MoveUp(n int) {
|
func (m *Model) MoveUp(n int) {
|
||||||
|
if m.cursor > firstRow {
|
||||||
|
m.SetCursor(m.cursor - n)
|
||||||
|
m.YOffset = m.YOffset - n
|
||||||
|
m.table.Offset(m.YOffset)
|
||||||
|
}
|
||||||
// check that the table has contents
|
// check that the table has contents
|
||||||
if len(m.rows) < 1 {
|
// if len(m.rows) < 1 {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
firstRow := firstRow
|
// firstRow := firstRow
|
||||||
m.SetCursor(m.cursor - n)
|
// m.SetCursor(m.cursor - n)
|
||||||
switch {
|
// switch {
|
||||||
case m.start == firstRow:
|
// case m.start == firstRow:
|
||||||
m.YOffset = clamp(m.YOffset, firstRow, m.cursor)
|
// m.YOffset = clamp(m.YOffset, firstRow, m.cursor)
|
||||||
case m.start < m.height:
|
// case m.start < m.height:
|
||||||
m.YOffset = (clamp(clamp(m.YOffset+n, firstRow, m.cursor), firstRow, m.height))
|
// m.YOffset = (clamp(clamp(m.YOffset+n, firstRow, m.cursor), firstRow, m.height))
|
||||||
case m.YOffset >= firstRow+1:
|
// case m.YOffset >= firstRow+1:
|
||||||
m.YOffset = clamp(m.YOffset+n, firstRow+1, m.height)
|
// m.YOffset = clamp(m.YOffset+n, firstRow+1, m.height)
|
||||||
}
|
// }
|
||||||
m.table.Offset(m.YOffset)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveDown moves the selection down by any number of rows.
|
// MoveDown moves the selection down by any number of rows.
|
||||||
// It can not go below the last row.
|
// It can not go below the last row.
|
||||||
func (m *Model) MoveDown(n int) {
|
func (m *Model) MoveDown(n int) {
|
||||||
m.SetCursor(m.cursor + n)
|
if m.cursor < len(m.rows) {
|
||||||
|
m.SetCursor(m.cursor + n)
|
||||||
switch {
|
m.YOffset = m.YOffset + n
|
||||||
case m.end == len(m.rows) && m.YOffset > 0:
|
m.table.Offset(m.YOffset)
|
||||||
m.YOffset = clamp(m.YOffset-n, 1, m.height)
|
|
||||||
case m.cursor > (m.end-m.start)/2 && m.YOffset > 0:
|
|
||||||
m.YOffset = clamp(m.YOffset-n, 1, m.cursor)
|
|
||||||
case m.YOffset > 1:
|
|
||||||
case m.cursor > m.YOffset+m.height-1:
|
|
||||||
m.YOffset = clamp(m.YOffset+1, 0, 1)
|
|
||||||
}
|
}
|
||||||
// update table offset
|
// TODO stop setting offset when visible rows less than expected
|
||||||
m.table.Offset(m.YOffset)
|
// TODO we should track visible row indices
|
||||||
}
|
}
|
||||||
|
|
||||||
// GotoTop moves the selection to the first row.
|
// GotoTop moves the selection to the first row.
|
||||||
|
|||||||
Reference in New Issue
Block a user