mirror of
https://github.com/Ascyii/typstar.git
synced 2025-12-31 21:14:25 -05:00
feat(snip): smart_jump() for node traversal
This commit is contained in:
@@ -52,11 +52,12 @@
|
||||
store_selection_keys = "<Tab>",
|
||||
})
|
||||
|
||||
require('typstar').setup()
|
||||
local typstar = require('typstar')
|
||||
typstar.setup({})
|
||||
|
||||
vim.keymap.set({'n', 'i'}, '<M-t>', '<Cmd>TypstarToggleSnippets<CR>', { silent = true, noremap = true })
|
||||
vim.keymap.set({'n', 'i'}, '<M-j>', function() ls.jump( 1) end, { silent = true, noremap = true })
|
||||
vim.keymap.set({'n', 'i'}, '<M-k>', function() ls.jump(-1) end, { silent = true, noremap = true })
|
||||
vim.keymap.set({'n', 'i'}, '<M-j>', '<Cmd>TypstarSmartJump<CR>', { silent = true, noremap = true })
|
||||
vim.keymap.set({'n', 'i'}, '<M-k>', '<Cmd>TypstarSmartJumpBack<CR>', { silent = true, noremap = true })
|
||||
EOF
|
||||
'';
|
||||
plugins = [
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
local config = require('typstar.config')
|
||||
local luasnip = nil
|
||||
|
||||
M.setup = function(args)
|
||||
config.merge_config(args)
|
||||
@@ -9,6 +10,8 @@ M.setup = function(args)
|
||||
local anki = require('typstar.anki')
|
||||
|
||||
vim.api.nvim_create_user_command('TypstarToggleSnippets', autosnippets.toggle_autosnippets, {})
|
||||
vim.api.nvim_create_user_command('TypstarSmartJump', function() M.smart_jump(1) end, {})
|
||||
vim.api.nvim_create_user_command('TypstarSmartJumpBack', function() M.smart_jump(-1) end, {})
|
||||
|
||||
vim.api.nvim_create_user_command('TypstarInsertExcalidraw', excalidraw.insert_drawing, {})
|
||||
vim.api.nvim_create_user_command('TypstarOpenExcalidraw', excalidraw.open_drawing, {})
|
||||
@@ -19,8 +22,23 @@ M.setup = function(args)
|
||||
vim.api.nvim_create_user_command('TypstarAnkiForceReimport', anki.scan_force_reimport, {})
|
||||
vim.api.nvim_create_user_command('TypstarAnkiForceCurrent', anki.scan_force_current, {})
|
||||
vim.api.nvim_create_user_command('TypstarAnkiForceCurrentReimport', anki.scan_force_current_reimport, {})
|
||||
|
||||
autosnippets.setup()
|
||||
end
|
||||
|
||||
-- source: https://github.com/lentilus/fastex.nvim
|
||||
M.smart_jump = function(length, x, y, tries)
|
||||
if luasnip == nil then luasnip = require('luasnip') end
|
||||
local x2, y2 = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local tries = tries or 0
|
||||
|
||||
if tries > 10 then return end
|
||||
if x == nil or y == nil then
|
||||
x, y = x2, y2
|
||||
end
|
||||
if x == x2 and y == y2 then
|
||||
luasnip.jump(length)
|
||||
vim.schedule(function() M.smart_jump(length, x, y, tries + 1) end)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user