Scrolling viewport issues #87
-
I'm working on a scrolling viewport for a file manager im building. There is a cursor to keep the currently selected file/folder that you are on as you scroll through them. When you reach the top of the list, I want to push the viewport to the bottom and set the cursor to the length of I have the following function created to deal with viewport position and cursor position as you go up or down the file tree: func (m *model) scrollViewport() {
top := m.viewport.YOffset
bottom := m.viewport.Height + m.viewport.YOffset - 1
if m.cursor < top {
m.viewport.LineUp(1)
} else if m.cursor > bottom {
m.viewport.LineDown(1)
}
if m.cursor > len(m.files)-1 {
m.cursor = 0
m.viewport.GotoTop()
} else if m.cursor < 0 {
m.cursor = len(m.files) - 1
m.viewport.GotoBottom()
}
} When I scroll down past the bottom of the currently viewable View of the viewport and then select a folder to open I receive the following error:
It's kind of hard to follow this, is there a way to get more info on where the error is coming from? The rest of the logic lives in https://github.com/knipferrc/fm/blob/main/src/update.go |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi! So if I understand correctly, you want the cursor to just back to the top when you reach the bottom, and vice-versa, yes? If so, I'm not able to reproduce the panic on my end when the list is taller than the viewport. That is, it's working great. The stack trace is probably the best way to figure out where the panic is happening as it's very specific, but you could also log to a file (Bubble Tea has the tea.LogToFile helper function for that), or debug with Delve. Anyway, do let me know how to do reproduce. This could be a bug in the viewport component. |
Beta Was this translation helpful? Give feedback.
Hi! So if I understand correctly, you want the cursor to just back to the top when you reach the bottom, and vice-versa, yes? If so, I'm not able to reproduce the panic on my end when the list is taller than the viewport. That is, it's working great.
The stack trace is probably the best way to figure out where the panic is happening as it's very specific, but you could also log to a file (Bubble Tea has the tea.LogToFile helper function for that), or debug with Delve.
Anyway, do let me know how to do reproduce. This could be a bug in the viewport component.