Make control to cmd translate on macos automatic

This commit is contained in:
Francesco Abbate 2021-04-21 10:16:51 +02:00
parent 12ca5f3d2a
commit 9d9c7f291c
2 changed files with 23 additions and 4 deletions

View File

@ -1,5 +1,5 @@
local function keymap_macos(keymap)
keymap.add {
keymap.add_direct {
["cmd+shift+p"] = "core:find-command",
["cmd+p"] = "core:find-file",
["cmd+o"] = "core:open-file",
@ -45,7 +45,7 @@ local function keymap_macos(keymap)
["cmd+x"] = "doc:cut",
["cmd+c"] = "doc:copy",
["cmd+v"] = "doc:paste",
["cmd+insert"] = "doc:copy",
["ctrl+insert"] = "doc:copy",
["shift+insert"] = "doc:paste",
["escape"] = { "command:escape", "doc:select-none", "dialog:select-no" },
["tab"] = { "command:complete", "doc:indent" },

View File

@ -23,11 +23,30 @@ local function key_to_stroke(k)
end
function keymap.add(map, overwrite)
function keymap.add_direct(map)
for stroke, commands in pairs(map) do
if type(commands) == "string" then
commands = { commands }
end
keymap.map[stroke] = commands
for _, cmd in ipairs(commands) do
keymap.reverse_map[cmd] = stroke
end
end
end
function keymap.add(map, overwrite)
local control_translate = function(s)
return macos and s:gsub("%f[%a]ctrl%f[%A]", "cmd") or s
end
for stroke, commands in pairs(map) do
if type(commands) == "string" then
commands = { control_translate(commands) }
else
for i = 1, #commands do
commands[i] = control_translate(commands[i])
end
end
if overwrite then
keymap.map[stroke] = commands
else
@ -85,7 +104,7 @@ if macos then
return keymap
end
keymap.add {
keymap.add_direct {
["ctrl+shift+p"] = "core:find-command",
["ctrl+p"] = "core:find-file",
["ctrl+o"] = "core:open-file",