Skip to content

Commit 4d9cebe

Browse files
committed
feat(tui): integrate goto modal with main tui system
- add `goto` key binding mapped to "g" or ":" key for slide navigation - add `goto` field to model struct to manage modal state - implement goto modal update logic with slide position calculation - add slide counting and navigation to specified slide number - integrate goto modal rendering in main view method
1 parent c18582d commit 4d9cebe

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
@@ -17,6 +17,7 @@ type keyMap struct {
1717
Top key.Binding
1818
Bottom key.Binding
1919
Command key.Binding
20+
GoTo key.Binding
2021
}
2122

2223
func (k keyMap) ShortHelp() []key.Binding {
@@ -52,6 +53,10 @@ var keys = keyMap{
5253
key.WithKeys("/", "p"),
5354
key.WithHelp("/, p", "command palette"),
5455
),
56+
GoTo: key.NewBinding(
57+
key.WithKeys("g", ":"),
58+
key.WithHelp("g, :", "go to slide"),
59+
),
5560
}
5661

5762
func style(width, height int, styleConfig config.StyleConfig) config.SlideStyle {
@@ -66,6 +71,7 @@ type model struct {
6671
keys keyMap
6772
help help.Model
6873
command *Command
74+
goTo *GoTo
6975
rootSlide *Slide
7076
}
7177

@@ -97,6 +103,27 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
97103
return m, cmd
98104
}
99105

106+
if m.goTo != nil && m.goTo.IsShowing() {
107+
goTo, cmd := m.goTo.Update(msg)
108+
m.goTo = &goTo
109+
110+
if goTo.Quitting() {
111+
if choice := goTo.Choice(); choice > 0 {
112+
// Find the slide at the specified position
113+
slide := m.rootSlide
114+
for i := 1; i < choice && slide != nil; i++ {
115+
slide = slide.Next
116+
}
117+
if slide != nil {
118+
m.slide = slide
119+
}
120+
}
121+
m.goTo = nil
122+
return m, nil
123+
}
124+
return m, cmd
125+
}
126+
100127
switch msg := msg.(type) {
101128
case UpdateSlidesMsg:
102129
// Find current position in the slide list
@@ -134,6 +161,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
134161
command = command.SetShowing(true)
135162
m.command = &command
136163
return m, nil
164+
} else if key.Matches(msg, m.keys.GoTo) {
165+
// Count total slides
166+
count := 0
167+
for slide := m.rootSlide; slide != nil; slide = slide.Next {
168+
count++
169+
}
170+
goTo := NewGoTo(count)
171+
goTo = goTo.SetShowing(true)
172+
m.goTo = &goTo
173+
return m, nil
137174
} else if key.Matches(msg, m.keys.Next) {
138175
if m.slide.Next == nil || m.slide.ActiveTransition != nil && m.slide.ActiveTransition.Animating() {
139176
return m, nil
@@ -185,5 +222,9 @@ func (m model) View() string {
185222
return m.command.Show(slideView, m.width, m.height)
186223
}
187224

225+
if m.goTo != nil && m.goTo.IsShowing() {
226+
return m.goTo.Show(slideView, m.width, m.height)
227+
}
228+
188229
return slideView
189230
}

0 commit comments

Comments
 (0)