Skip to content

Commit

Permalink
feat(venn-nvim): allow using Hydra if it's available to create a draw…
Browse files Browse the repository at this point in the history
…ing submode
  • Loading branch information
mehalter committed Apr 26, 2024
1 parent 237daaf commit ab4e806
Showing 1 changed file with 92 additions and 35 deletions.
127 changes: 92 additions & 35 deletions lua/astrocommunity/note-taking/venn-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,43 +1,100 @@
local hint = [[
Arrow^^^^^^ Select region with <C-v>
^ ^ _K_ ^ ^ _f_: surround it with box
_H_ ^ ^ _L_
^ ^ _J_ ^ ^ _<Esc>_
]]

return {
"jbyuki/venn.nvim",
cmd = "VBox",
dependencies = {
"AstroNvim/astrocore",
---@type AstroCoreOpts
opts = {
commands = {
ToggleVenn = {
function()
local mappings = {
n = { -- draw a line on HJKL keystokes
H = "<C-v>h:VBox<CR>",
J = "<C-v>j:VBox<CR>",
K = "<C-v>k:VBox<CR>",
L = "<C-v>l:VBox<CR>",
{
"jbyuki/venn.nvim",
cmd = "VBox",
dependencies = {
{
"AstroNvim/astrocore",
opts = function(_, opts)
local astrocore = require "astrocore"
if astrocore.is_available "hydra.nvim" then
if not opts.commands then opts.comands = {} end
opts.commands.ToggleVenn = {
function()
local hydra = vim.tbl_get(astrocore.plugin_opts "hydra.nvim", "Draw Diagram", "hydra")
if hydra then
if hydra.layer.active then
hydra:exit()
else
hydra:activate()
end
end
end,
desc = "Toggle venn diagramming mode",
}
else
return astrocore.extend_tbl(opts, {
commands = {
ToggleVenn = {
function()
local mappings = {
n = { -- draw a line on HJKL keystokes
H = "<C-v>h:VBox<CR>",
J = "<C-v>j:VBox<CR>",
K = "<C-v>k:VBox<CR>",
L = "<C-v>l:VBox<CR>",
},
v = { -- draw a box by pressing "f" with visual selection
f = ":VBox<CR>",
},
}
if vim.b.venn_enabled then
vim.opt_local.virtualedit = ""
for mode, map in pairs(mappings) do
for lhs, _ in pairs(map) do
vim.keymap.del(mode, lhs, { buffer = true })
end
end
vim.b.venn_enabled = nil
else
vim.b.venn_enabled = true
vim.opt_local.virtualedit = "all"
require("astrocore").set_mappings(mappings, { buffer = true })
end
vim.notify(("Venn Diagramming Mode: %s"):format(vim.b.venn_enabled and "Enabled" or "Disabled"))
end,
desc = "Toggle venn diagramming mode",
},
},
v = { -- draw a box by pressing "f" with visual selection
f = ":VBox<CR>",
mappings = {
n = { ["<Leader>v"] = { function() vim.cmd.ToggleVenn() end, desc = "Toggle venn diagramming" } },
},
}
if vim.b.venn_enabled then
vim.opt_local.virtualedit = ""
for mode, map in pairs(mappings) do
for lhs, _ in pairs(map) do
vim.keymap.del(mode, lhs, { buffer = true })
end
end
vim.b.venn_enabled = nil
else
vim.b.venn_enabled = true
vim.opt_local.virtualedit = "all"
require("astrocore").set_mappings(mappings, { buffer = true })
end
vim.notify(("Venn Diagramming Mode: %s"):format(vim.b.venn_enabled and "Enabled" or "Disabled"))
end,
desc = "Toggle venn diagramming mode",
})
end
end,
},
},
},
{
"anuvyklack/hydra.nvim",
optional = true,
opts = {
["Draw Diagram"] = {
hint = hint,
config = {
color = "pink",
invoke_on_body = true,
hint = { border = "rounded" },
on_enter = function() vim.o.virtualedit = "all" end,
},
mode = "n",
body = "<leader>v",
heads = {
{ "H", "<C-v>h:VBox<CR>" },
{ "J", "<C-v>j:VBox<CR>" },
{ "K", "<C-v>k:VBox<CR>" },
{ "L", "<C-v>l:VBox<CR>" },
{ "f", ":VBox<CR>", { mode = "v" } },
{ "<Esc>", nil, { exit = true } },
},
},
mappings = { n = { ["<Leader>v"] = { function() vim.cmd.ToggleVenn() end, desc = "Toggle venn diagramming" } } },
},
},
}

0 comments on commit ab4e806

Please sign in to comment.