@@ -14,6 +14,18 @@ local ALL_MODES = {
1414 ' resize' ,
1515}
1616
17+ local function changeMode (mode , stickyValue )
18+ state .currentMode = mode
19+ if stickyValue ~= nil then
20+ state .sticky = stickyValue
21+ end
22+ local display = state .currentMode
23+ if state .sticky then
24+ display = display .. ' (sticky)'
25+ end
26+ api .setPlaceholderValue (' vi-mode' , display )
27+ end
28+
1729---- ----------------
1830-- KEYBINDINGS: --
1931---- ----------------
@@ -88,135 +100,127 @@ local keybindings = {
88100 buttons = { ' t' },
89101 modes = ALL_MODES ,
90102 call = function ()
91- state .currentMode = ' tool'
92- state .sticky = false
103+ changeMode (' tool' , false )
93104 end ,
94105 },
95106 color = {
96107 description = ' Color mode' ,
97108 buttons = { ' c' },
98109 modes = { ' tool' },
99110 call = function ()
100- state . currentMode = ' color'
111+ changeMode ( ' color' )
101112 end ,
102113 },
103114 stickyColor = {
104115 description = ' Sticky color mode' ,
105116 buttons = { ' <Shift>c' },
106117 modes = { ' tool' },
107118 call = function ()
108- state .currentMode = ' color'
109- state .sticky = true
119+ changeMode (' color' , true )
110120 end ,
111121 },
112122 shape = {
113123 description = ' Shape mode' ,
114124 buttons = { ' a' },
115125 modes = { ' tool' },
116126 call = function ()
117- state . currentMode = ' shape'
127+ changeMode ( ' shape' )
118128 end ,
119129 },
120130 stickyShape = {
121131 description = ' Sticky shape mode' ,
122132 buttons = { ' <Shift>a' },
123133 modes = { ' tool' },
124134 call = function ()
125- state .currentMode = ' shape'
126- state .sticky = true
135+ changeMode (' shape' , true )
127136 end ,
128137 },
129138 linestyle = {
130139 description = ' Linestyle mode' ,
131140 buttons = { ' q' },
132141 modes = { ' tool' },
133142 call = function ()
134- state . currentMode = ' linestyle'
143+ changeMode ( ' linestyle' )
135144 end ,
136145 },
137146 stickyLinestyle = {
138147 description = ' Sticky linestyle mode' ,
139148 buttons = { ' <Shift>q' },
140149 modes = { ' tool' },
141150 call = function ()
142- state .currentMode = ' linestyle'
143- state .sticky = true
151+ changeMode (' linestyle' , true )
144152 end ,
145153 },
146154 page = {
147155 description = ' Page mode' ,
148156 buttons = { ' b' , ' p' },
149157 modes = { ' tool' },
150158 call = function ()
151- state . currentMode = ' page'
159+ changeMode ( ' page' )
152160 end ,
153161 },
154162 stickyPage = {
155163 description = ' Sticky page mode' ,
156164 buttons = { ' <Shift>b' , ' <Shift>p' },
157165 modes = { ' tool' },
158166 call = function ()
159- state .currentMode = ' page'
160- state .sticky = true
167+ changeMode (' page' , true )
161168 end ,
162169 },
163170 navigation = {
164171 description = ' Navigation mode' ,
165172 buttons = { ' g' },
166173 modes = { ' tool' },
167174 call = function ()
168- state . currentMode = ' navigation'
175+ changeMode ( ' navigation' )
169176 end ,
170177 },
171178 stickyNavigation = {
172179 description = ' Sticky navigation mode' ,
173180 buttons = { ' <Shift>g' },
174181 modes = { ' tool' },
175182 call = function ()
176- state .currentMode = ' navigation'
177- state .sticky = true
183+ changeMode (' navigation' , true )
178184 end ,
179185 },
180186 file = {
181187 description = ' File mode' ,
182188 buttons = { ' y' },
183189 modes = { ' tool' },
184190 call = function ()
185- state . currentMode = ' file'
191+ changeMode ( ' file' )
186192 end ,
187193 },
188194 stickyFile = {
189195 description = ' Sticky file mode' ,
190196 buttons = { ' <Shift>y' },
191197 modes = { ' tool' },
192198 call = function ()
193- state .currentMode = ' file'
194- state .sticky = true
199+ changeMode (' file' , true )
195200 end ,
196201 },
197202 visual = {
198203 description = ' Visual mode' ,
199204 buttons = { ' v' },
200205 modes = { ' tool' },
201206 call = function ()
202- state . currentMode = ' visual'
207+ changeMode ( ' visual' )
203208 end ,
204209 },
205210 stickyVisual = {
206211 description = ' Sticky visual mode' ,
207212 buttons = { ' <Shift>v' },
208213 modes = { ' tool' },
209214 call = function ()
210- state .currentMode = ' visual'
211- state .sticky = true
215+ changeMode (' visual' , true )
212216 end ,
213217 },
214218 resize = {
215219 description = ' Resize mode' ,
216220 buttons = { ' <Shift>F' },
217221 modes = { ' tool' },
218222 call = function ()
219- state . currentMode = ' resize'
223+ changeMode ( ' resize' )
220224 end ,
221225 },
222226
662666return {
663667 bindings = keybindings ,
664668 ALL_MODES = ALL_MODES ,
669+ changeMode = changeMode ,
665670}
0 commit comments