mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
fix(filepicker): push / pop views
This commit is contained in:
+15
-11
@@ -190,13 +190,13 @@ func newStack() stack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) pushView() {
|
func (m *Model) pushView(selected, min, max int) {
|
||||||
m.minStack.Push(m.min)
|
m.selectedStack.Push(selected)
|
||||||
m.maxStack.Push(m.max)
|
m.minStack.Push(min)
|
||||||
m.selectedStack.Push(m.selected)
|
m.maxStack.Push(max)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) popView() (int, int, int) {
|
func (m *Model) popView() (int, int, int) {
|
||||||
return m.selectedStack.Pop(), m.minStack.Pop(), m.maxStack.Pop()
|
return m.selectedStack.Pop(), m.minStack.Pop(), m.maxStack.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +243,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
m.files = msg.entries
|
m.files = msg.entries
|
||||||
m.max = m.Height - 1
|
m.max = max(m.max, m.Height-1)
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
if m.AutoHeight {
|
if m.AutoHeight {
|
||||||
m.Height = msg.Height - marginBottom
|
m.Height = msg.Height - marginBottom
|
||||||
@@ -347,7 +347,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.CurrentDirectory = filepath.Join(m.CurrentDirectory, f.Name())
|
m.CurrentDirectory = filepath.Join(m.CurrentDirectory, f.Name())
|
||||||
m.pushView()
|
m.pushView(m.selected, m.min, m.max)
|
||||||
m.selected = 0
|
m.selected = 0
|
||||||
m.min = 0
|
m.min = 0
|
||||||
m.max = m.Height - 1
|
m.max = m.Height - 1
|
||||||
@@ -365,12 +365,9 @@ func (m Model) View() string {
|
|||||||
var s strings.Builder
|
var s strings.Builder
|
||||||
|
|
||||||
for i, f := range m.files {
|
for i, f := range m.files {
|
||||||
if i < m.min {
|
if i < m.min || i > m.max {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i > m.max {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
var symlinkPath string
|
var symlinkPath string
|
||||||
info, _ := f.Info()
|
info, _ := f.Info()
|
||||||
@@ -498,3 +495,10 @@ func (m Model) canSelect(file string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func max(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user