Skip to content

Commit

Permalink
fix: focus/events pager
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Dec 6, 2024
1 parent 4d2010c commit ed4c78e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions pager/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (o Options) Run() error {
m,
tea.WithAltScreen(),
tea.WithContext(ctx),
tea.WithReportFocus(),
).Run()
if err != nil {
return fmt.Errorf("unable to start program: %w", err)
Expand Down
10 changes: 7 additions & 3 deletions pager/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strings"

"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand Down Expand Up @@ -34,10 +35,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
m.ProcessText(msg)
case tea.KeyMsg:
return m.KeyHandler(msg)
return m.keyHandler(msg)
}

return m, nil
var cmd tea.Cmd
m.search.input, cmd = m.search.input.Update(msg)
return m, cmd
}

func (m *model) ProcessText(msg tea.WindowSizeMsg) {
Expand Down Expand Up @@ -84,7 +87,7 @@ func (m *model) ProcessText(msg tea.WindowSizeMsg) {

const heightOffset = 2

func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
func (m model) keyHandler(key tea.KeyMsg) (model, tea.Cmd) {
var cmd tea.Cmd
if m.search.active {
switch key.String() {
Expand Down Expand Up @@ -112,6 +115,7 @@ func (m model) KeyHandler(key tea.KeyMsg) (model, func() tea.Msg) {
m.viewport.GotoBottom()
case "/":
m.search.Begin()
return m, textinput.Blink
case "p", "N":
m.search.PrevMatch(&m)
m.ProcessText(tea.WindowSizeMsg{Height: m.viewport.Height + heightOffset, Width: m.viewport.Width})
Expand Down

0 comments on commit ed4c78e

Please sign in to comment.