Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
koki-develop committed Mar 26, 2023
1 parent d00ccf9 commit 76ee2cf
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions model.go
Expand Up @@ -152,8 +152,12 @@ func (m *model) itemsView() string {

headerHeight := m.headerHeight()

for i, match := range m.matches[m.windowYPosition:] {
cursorLine := m.cursorPosition == i+m.windowYPosition
for i, match := range m.matches {
if i < m.windowYPosition {
continue
}

cursorLine := m.cursorPosition == i

// write cursor
if cursorLine {
Expand Down Expand Up @@ -192,7 +196,7 @@ func (m *model) itemsView() string {
}
}

if i+1 >= m.windowHeight-headerHeight {
if i+1-m.windowYPosition >= m.windowHeight-headerHeight {
break
}
v.WriteString("\n")
Expand All @@ -209,6 +213,11 @@ type watchReloadMsg struct{}
type forceReloadMsg struct{}

func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.option.hotReloadLocker != nil {
m.option.hotReloadLocker.Lock()
defer m.option.hotReloadLocker.Unlock()
}

switch msg := msg.(type) {
case tea.KeyMsg:
// key
Expand Down Expand Up @@ -259,10 +268,6 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd)
}
if beforeValue != m.input.Value() {
if m.option.hotReloadLocker != nil {
m.option.hotReloadLocker.Lock()
defer m.option.hotReloadLocker.Unlock()
}
m.filter()
m.fixYPosition()
m.fixCursor()
Expand Down Expand Up @@ -359,16 +364,11 @@ func (m *model) fixYPosition() {
}

func (m *model) forceReload() {
m.option.hotReloadLocker.Lock()
defer m.option.hotReloadLocker.Unlock()
m.loadItems(m.items)
}

func (m *model) watchReload() tea.Cmd {
return tea.Tick(30*time.Millisecond, func(_ time.Time) tea.Msg {
m.option.hotReloadLocker.Lock()
defer m.option.hotReloadLocker.Unlock()

if m.itemsLen != m.items.Len() {
m.loadItems(m.items)
}
Expand Down

0 comments on commit 76ee2cf

Please sign in to comment.