Skip to content

Commit 1e5a3cb

Browse files
feat: vi-mode indicator
1 parent f953c40 commit 1e5a3cb

5 files changed

Lines changed: 51 additions & 25 deletions

File tree

api/registry.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,12 @@ return {
366366
getToolInfo = {
367367
{ impl = wrapper.getToolInfo, deps = { 'getToolInfo' } },
368368
},
369+
370+
-- PLACEHOLDER
371+
registerPlaceholder = {
372+
{ impl = wrapper.registerPlaceholder, deps = { 'registerPlaceholder' } },
373+
},
374+
setPlaceholderValue = {
375+
{ impl = wrapper.setPlaceholderValue, deps = { 'setPlaceholderValue' } },
376+
},
369377
}

api/wrapper.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,13 @@ wrapper.getToolInfo = function(tool)
325325
return app.getToolInfo(tool)
326326
end
327327

328+
-- PLACEHOLDER
329+
wrapper.registerPlaceholder = function(name, description)
330+
app.registerPlaceholder(name, description)
331+
end
332+
333+
wrapper.setPlaceholderValue = function(placeholder, val)
334+
app.setPlaceholderValue(placeholder, val)
335+
end
336+
328337
return wrapper

keybindings.lua

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -662,4 +666,5 @@ end
662666
return {
663667
bindings = keybindings,
664668
ALL_MODES = ALL_MODES,
669+
changeMode = changeMode,
665670
}

main.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package.path = script_path .. '?.lua;' .. script_path .. '?/init.lua;' .. packag
44

55
local utils = require('utils')
66
local log = utils.log
7+
local api = require('api')
78

89
local kb_module = require('keybindings')
910
local keybindings = kb_module.bindings
@@ -62,6 +63,8 @@ end
6263
-- xournalpp require `initUi` as name
6364
---@diagnostic disable-next-line: lowercase-global
6465
function initUi()
66+
api.registerPlaceholder('vi-mode', 'Vi Mode Indicator')
67+
6568
local index = 1
6669
local skipped = {}
6770

modes.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ local state = require('state')
44

55
local kb_module = require('keybindings')
66
local keybindings = kb_module.bindings
7+
local changeMode = kb_module.changeMode
78

89
local function handle(key)
910
for _, binding in pairs(keybindings) do
1011
if binding.button_set[key] and binding.mode_set[state.currentMode] then
1112
if state.currentMode ~= 'tool' and not state.sticky then
12-
state.currentMode = 'tool'
13+
changeMode('tool')
1314
end
1415

1516
if binding.call then

0 commit comments

Comments
 (0)