Skip to content

Commit 6a1e344

Browse files
committed
add ability to bind defold actions to keymaps
1 parent b936aeb commit 6a1e344

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ local config = {
153153
custom_executable = nil,
154154
},
155155

156+
-- setup keymaps for Defold actions
157+
keymaps = {
158+
159+
-- build (& run) action
160+
build = {
161+
-- make this available in normal and insert mode
162+
mode = { "n", "i" },
163+
164+
-- run via Ctrl+b
165+
mapping = "<C-b>",
166+
},
167+
},
168+
156169
-- Force the plugin to be always enabled (even if we can't find the game.project file) (default: false)
157170
force_plugin_enabled = false,
158171
}

lua/defold/init.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ local root_markers = { "game.project" }
2323
---@class BabashkaSettings Settings for the integrated Babashka interpreter
2424
---@field custom_executable string|nil Use a custom executable for babashka
2525

26+
---@class Keymap
27+
---@field mode string|string[]
28+
---@field mapping string
29+
2630
---@class DefoldNvimConfig Settings for defold.nvim
2731
---@field defold DefoldEditorSettings Settings for the Defold Game Engine
2832
---@field launcher LauncherSettings Settings for the Neovim launcher run by Defold
2933
---@field debugger DebuggerSettings Settings for the integrated debugger
3034
---@field babashka BabashkaSettings Settings for the integrated Babashka interpreter
35+
---@field keymaps table<string, Keymap>|nil Settings for key -> action mappings
3136
---@field force_plugin_enabled boolean Force the plugin to be always enabled (even if we can't find the game.project file)
3237

3338
---@type DefoldNvimConfig
@@ -56,6 +61,13 @@ local default_config = {
5661
custom_executable = nil,
5762
},
5863

64+
keymaps = {
65+
build = {
66+
mode = { "n", "i" },
67+
mapping = "<C-b>",
68+
},
69+
},
70+
5971
force_plugin_enabled = false,
6072
}
6173

@@ -272,6 +284,15 @@ function M.load_plugin()
272284
-- add icons
273285
require("defold.service.icons").install()
274286

287+
-- setup keymaps
288+
for action, keymap in pairs(M.config.keymaps) do
289+
log.debug(string.format("Setup action '%s' for keymap '%s'", action, vim.json.encode(keymap)))
290+
291+
vim.keymap.set(keymap.mode, keymap.mapping, function()
292+
editor.send_command(action)
293+
end)
294+
end
295+
275296
-- fetch dependencies
276297
if M.config.defold.auto_fetch_dependencies then
277298
project.install_dependencies(false)

0 commit comments

Comments
 (0)