From 4812bdd7dc889ab743e1db40337a611af8266efd Mon Sep 17 00:00:00 2001 From: Max <55395652+kontr0x@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:05:45 +0100 Subject: [PATCH] Update markview keyboard shortcut - Update the keyboard shortcut to imitate Joplin behavior --- lua/custom/plugins/init.lua | 59 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index d8dfd9b1..4170ae60 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -3,34 +3,37 @@ -- -- See the kickstart.nvim README for more information return { - { - 'OXY2DEV/markview.nvim', - lazy = false, -- Recommended - -- ft = "markdown" -- If you decide to lazy-load anyway - - dependencies = { - 'nvim-treesitter/nvim-treesitter', - 'nvim-tree/nvim-web-devicons', - }, + { + 'OXY2DEV/markview.nvim', + lazy = false, -- Recommended + -- ft = "markdown" -- If you decide to lazy-load anyway - opts = { - initial_state = false, - }, - config = function(_, opts) - require('markview').setup(opts) - - local splitToggle_state = false - vim.keymap.set('n', '', function() - if not splitToggle_state then - -- The split toggle will not work unless markview is disabled in the initial window beforehand - vim.cmd 'Markview disableAll' - vim.cmd 'Markview splitEnable' - splitToggle_state = true - else - vim.cmd 'Markview splitDisable' - splitToggle_state = false - end - end, { silent = true, desc = 'Toggle Markview split view' }) - end, + dependencies = { + 'nvim-treesitter/nvim-treesitter', + 'nvim-tree/nvim-web-devicons', }, + + opts = { + initial_state = false, + }, + config = function(_, opts) + require('markview').setup(opts) + + -- This function imitates the behavior of Joplin when rendering notes + local splitToggle_state = 0 + vim.keymap.set('n', '', function() + if splitToggle_state == 0 then + vim.cmd 'Markview enableAll' + splitToggle_state = 1 + elseif splitToggle_state == 1 then + vim.cmd 'Markview splitEnable' + splitToggle_state = 2 + else + vim.cmd 'Markview splitDisable' + vim.cmd 'Markview disableAll' + splitToggle_state = 0 + end + end, { silent = true, desc = 'Toggle Markview split view' }) + end, + }, }