Skip to content

Commit 3ccdb83

Browse files
committed
feat(tui): integrate jump component into main tui model
- add `Jump` key binding for number keys 1-9 in keymap - add jump field to main model struct - implement jump mode activation and navigation logic - handle forward and backward slide jumping with step counts - integrate jump overlay display in main view rendering
1 parent 4860014 commit 3ccdb83

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

internal/tui/tui.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type keyMap struct {
1818
Bottom key.Binding
1919
Command key.Binding
2020
GoTo key.Binding
21+
Jump key.Binding
2122
}
2223

2324
func (k keyMap) ShortHelp() []key.Binding {
@@ -57,6 +58,10 @@ var keys = keyMap{
5758
key.WithKeys("g", ":"),
5859
key.WithHelp("g, :", "go to slide"),
5960
),
61+
Jump: key.NewBinding(
62+
key.WithKeys("1", "2", "3", "4", "5", "6", "7", "8", "9"),
63+
key.WithHelp("1-9", "jump slides"),
64+
),
6065
}
6166

6267
func style(width, height int, styleConfig config.StyleConfig) config.SlideStyle {
@@ -72,6 +77,7 @@ type model struct {
7277
help help.Model
7378
command *Command
7479
goTo *GoTo
80+
jump *Jump
7581
rootSlide *Slide
7682
}
7783

@@ -124,6 +130,30 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
124130
return m, cmd
125131
}
126132

133+
if m.jump != nil && m.jump.IsShowing() {
134+
jump, cmd := m.jump.Update(msg)
135+
m.jump = &jump
136+
137+
if jump.Quitting() {
138+
if steps := jump.JumpSteps(); steps != 0 {
139+
if steps > 0 {
140+
// Jump forward
141+
for i := 0; i < steps && m.slide.Next != nil; i++ {
142+
m.slide = m.slide.Next
143+
}
144+
} else {
145+
// Jump backward
146+
for i := 0; i < -steps && m.slide.Prev != nil; i++ {
147+
m.slide = m.slide.Prev
148+
}
149+
}
150+
}
151+
m.jump = nil
152+
return m, nil
153+
}
154+
return m, cmd
155+
}
156+
127157
switch msg := msg.(type) {
128158
case UpdateSlidesMsg:
129159
// Find current position in the slide list
@@ -171,6 +201,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
171201
goTo = goTo.SetShowing(true)
172202
m.goTo = &goTo
173203
return m, nil
204+
} else if key.Matches(msg, m.keys.Jump) {
205+
jump := NewJump()
206+
jump = jump.SetShowing(true)
207+
m.jump = &jump
208+
jump, cmd := jump.Update(msg)
209+
m.jump = &jump
210+
return m, cmd
174211
} else if key.Matches(msg, m.keys.Next) {
175212
if m.slide.Next == nil || m.slide.ActiveTransition != nil && m.slide.ActiveTransition.Animating() {
176213
return m, nil
@@ -226,5 +263,9 @@ func (m model) View() string {
226263
return m.goTo.Show(slideView, m.width, m.height)
227264
}
228265

266+
if m.jump != nil && m.jump.IsShowing() {
267+
return m.jump.Show(slideView, m.width, m.height)
268+
}
269+
229270
return slideView
230271
}

0 commit comments

Comments
 (0)