@@ -11,11 +11,12 @@ import (
11
11
)
12
12
13
13
type keyMap struct {
14
- Quit key.Binding
15
- Next key.Binding
16
- Prev key.Binding
17
- Top key.Binding
18
- Bottom key.Binding
14
+ Quit key.Binding
15
+ Next key.Binding
16
+ Prev key.Binding
17
+ Top key.Binding
18
+ Bottom key.Binding
19
+ Command key.Binding
19
20
}
20
21
21
22
func (k keyMap ) ShortHelp () []key.Binding {
@@ -47,6 +48,10 @@ var keys = keyMap{
47
48
key .WithKeys ("end" , "shift+down" , "$" ),
48
49
key .WithHelp ("end, shift+down, $" , "bottom" ),
49
50
),
51
+ Command : key .NewBinding (
52
+ key .WithKeys ("?" , "p" ),
53
+ key .WithHelp ("ctrl+p, p" , "command palette" ),
54
+ ),
50
55
}
51
56
52
57
func style (width , height int , styleConfig config.StyleConfig ) config.SlideStyle {
@@ -57,16 +62,19 @@ type model struct {
57
62
width int
58
63
height int
59
64
60
- slide * Slide
61
- keys keyMap
62
- help help.Model
65
+ slide * Slide
66
+ keys keyMap
67
+ help help.Model
68
+ command * Command
69
+ rootSlide * Slide
63
70
}
64
71
65
72
func New (rootSlide * Slide ) model {
66
73
return model {
67
- slide : rootSlide ,
68
- keys : keys ,
69
- help : help .New (),
74
+ slide : rootSlide ,
75
+ keys : keys ,
76
+ help : help .New (),
77
+ rootSlide : rootSlide ,
70
78
}
71
79
}
72
80
@@ -75,6 +83,20 @@ func (m model) Init() tea.Cmd {
75
83
}
76
84
77
85
func (m model ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
86
+ if m .command != nil && m .command .IsShowing () {
87
+ command , cmd := m .command .Update (msg )
88
+ m .command = & command
89
+
90
+ if command .quitting || command .Choice () != nil {
91
+ if command .Choice () != nil {
92
+ m .slide = command .Choice ()
93
+ }
94
+ m .command = nil
95
+ return m , nil
96
+ }
97
+ return m , cmd
98
+ }
99
+
78
100
switch msg := msg .(type ) {
79
101
case UpdateSlidesMsg :
80
102
// Find current position in the slide list
@@ -85,6 +107,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
85
107
86
108
// Update root and navigate to the same position in the new list
87
109
m .slide = msg .NewRoot
110
+ m .rootSlide = msg .NewRoot
88
111
for i := 0 ; i < currentPosition && m .slide != nil ; i ++ {
89
112
m .slide = m .slide .Next
90
113
}
@@ -106,6 +129,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
106
129
case tea.KeyMsg :
107
130
if key .Matches (msg , m .keys .Quit ) {
108
131
return m , tea .Quit
132
+ } else if key .Matches (msg , m .keys .Command ) {
133
+ palette := NewCommand (m .rootSlide )
134
+ palette = palette .SetShowing (true )
135
+ m .command = & palette
136
+ return m , nil
109
137
} else if key .Matches (msg , m .keys .Next ) {
110
138
if m .slide .Next == nil || m .slide .ActiveTransition != nil && m .slide .ActiveTransition .Animating () {
111
139
return m , nil
@@ -145,11 +173,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
145
173
func (m model ) View () string {
146
174
m .slide .Style = style (m .width , m .height , m .slide .Properties .Style )
147
175
148
- return lipgloss .Place (
176
+ slideView := lipgloss .Place (
149
177
m .width ,
150
178
m .height ,
151
179
lipgloss .Center ,
152
180
lipgloss .Center ,
153
181
m .slide .View (),
154
182
)
183
+
184
+ if m .command != nil && m .command .IsShowing () {
185
+ return m .command .Show (slideView , m .width , m .height )
186
+ }
187
+
188
+ return slideView
155
189
}
0 commit comments