Clean up the logic a bit and user diff api.
This commit is contained in:
parent
798c6eb608
commit
c1744a5e81
@ -2,35 +2,27 @@ local M = {}
|
|||||||
local header_regex = "^(#+) (.+)"
|
local header_regex = "^(#+) (.+)"
|
||||||
|
|
||||||
M.promote = function()
|
M.promote = function()
|
||||||
if vim.api.nvim_get_mode().mode == "n" then
|
|
||||||
local current_line = vim.api.nvim_get_current_line()
|
local current_line = vim.api.nvim_get_current_line()
|
||||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
local new_line = ""
|
|
||||||
|
|
||||||
if current_line:match(header_regex) then
|
if current_line:match(header_regex) then
|
||||||
if current_line:match("^# (.+)") then
|
if current_line:match("^# (.+)") then
|
||||||
vim.notify("You can't promote this header anymore")
|
vim.notify("You can't promote this header anymore")
|
||||||
return
|
else
|
||||||
end
|
vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 1, { '' })
|
||||||
new_line = current_line:gsub("^#", "", 1)
|
|
||||||
vim.api.nvim_buf_set_lines(0, row - 1, row, true, { new_line })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.demote = function()
|
M.demote = function()
|
||||||
if vim.api.nvim_get_mode().mode == "n" then
|
|
||||||
local current_line = vim.api.nvim_get_current_line()
|
local current_line = vim.api.nvim_get_current_line()
|
||||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
local new_line = ""
|
|
||||||
|
|
||||||
if current_line:match(header_regex) then
|
if current_line:match(header_regex) then
|
||||||
if current_line:match("^###### (.+)") then
|
if current_line:match("^###### (.+)") then
|
||||||
vim.notify("You can't demote this header anymore")
|
vim.notify("You can't demote this header anymore")
|
||||||
return
|
else
|
||||||
end
|
vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 0, { '#' })
|
||||||
new_line = current_line:gsub("^#", "##", 1)
|
|
||||||
vim.api.nvim_buf_set_lines(0, row - 1, row, true, { new_line })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user