mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 13:34:24 -05:00
Add deletion for drawings
This commit is contained in:
@@ -104,10 +104,64 @@ local open_drawing = function(prov)
|
||||
end
|
||||
end
|
||||
|
||||
local function delete_drawing(provider)
|
||||
local cfg = provider[1]
|
||||
local line_num = vim.api.nvim_win_get_cursor(0)[1] - 1
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||
|
||||
-- Find the start and end of the #figure() block containing the filename
|
||||
local start_line, end_line
|
||||
for i = line_num, 0, -1 do
|
||||
if lines[i + 1]:match("^#figure%(") then
|
||||
start_line = i
|
||||
break
|
||||
end
|
||||
end
|
||||
for i = line_num, #lines - 1 do
|
||||
if lines[i + 1]:match("%)$") then
|
||||
end_line = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not start_line or not end_line then
|
||||
print("No #figure() block found on current line")
|
||||
return
|
||||
end
|
||||
|
||||
-- Extract filename from the block
|
||||
local block_text = table.concat(vim.api.nvim_buf_get_lines(0, start_line, end_line + 1, false), "\n")
|
||||
local filename = block_text:match('image%("%s*(.-)%s*"%)')
|
||||
if not filename then
|
||||
print("No image filename found in #figure() block")
|
||||
return
|
||||
end
|
||||
|
||||
local path = vim.fn.expand('%:p:h') .. '/' .. filename
|
||||
local path_export = vim.fn.expand('%:p:h') .. '/' .. filename:match("^(.*)%.")
|
||||
|
||||
-- Delete files if they exist
|
||||
if vim.fn.filereadable(path) == 1 then os.remove(path) end
|
||||
if vim.fn.filereadable(path_export) == 1 then os.remove(path_export) end
|
||||
|
||||
-- Delete the lines of the #figure() block
|
||||
vim.api.nvim_buf_set_lines(0, start_line, end_line + 1, false, {})
|
||||
|
||||
print("Deleted drawing: " .. filename)
|
||||
end
|
||||
|
||||
function M.delete_obsidian_excalidraw() delete_drawing(excalidraw) end
|
||||
|
||||
function M.delete_rnote() delete_drawing(rnote) end
|
||||
|
||||
function M.insert_obsidian_excalidraw() insert_drawing(excalidraw) end
|
||||
|
||||
function M.insert_rnote() insert_drawing(rnote) end
|
||||
|
||||
function M.open_obsidian_excalidraw() open_drawing({ excalidraw }) end
|
||||
|
||||
function M.open_rnote() open_drawing({ rnote }) end
|
||||
|
||||
function M.open_drawing() open_drawing(providers) end
|
||||
|
||||
return M
|
||||
|
||||
@@ -14,7 +14,9 @@ M.setup = function(args)
|
||||
vim.api.nvim_create_user_command('TypstarSmartJumpBack', function() M.smart_jump(-1) end, {})
|
||||
|
||||
vim.api.nvim_create_user_command('TypstarInsertExcalidraw', drawings.insert_obsidian_excalidraw, {})
|
||||
vim.api.nvim_create_user_command('TypstarDeleteExcalidraw', drawings.delete_obsidian_excalidraw, {})
|
||||
vim.api.nvim_create_user_command('TypstarInsertRnote', drawings.insert_rnote, {})
|
||||
vim.api.nvim_create_user_command('TypstarDeleteRnote', drawings.delete_rnote, {})
|
||||
vim.api.nvim_create_user_command('TypstarOpenExcalidraw', drawings.open_obsidian_excalidraw, {})
|
||||
vim.api.nvim_create_user_command('TypstarOpenRnote', drawings.open_rnote, {})
|
||||
vim.api.nvim_create_user_command('TypstarOpenDrawing', drawings.open_drawing, {})
|
||||
|
||||
@@ -38,10 +38,13 @@ return {
|
||||
snip('pl', '+ ', {}, math),
|
||||
snip('nl', '\\ \n<>', {i(1)}, math),
|
||||
snip('pm', '+- ', {}, math),
|
||||
snip('nx', ', space ', {}, math),
|
||||
snip('nbx', ', quad ', {}, math),
|
||||
snip('nx', '\\, space ', {}, math),
|
||||
snip('nbx', '\\, quad ', {}, math),
|
||||
snip('deg', 'degree ', {}, math),
|
||||
snip('ta', 'star ', {}, math),
|
||||
snip('del', 'Delta ', {}, math),
|
||||
snip('apr', 'approx ', {}, math),
|
||||
snip('pal', 'parallel ', {}, math),
|
||||
|
||||
-- operators
|
||||
snip('ak([^k ])', '+ <>', { cap(1) }, math, 100, { wordTrig = false }),
|
||||
|
||||
Reference in New Issue
Block a user