Updated actions/init.lua
Added actions@hyperlink_exec. Responsible for acting upon an execution call from keybinding. Function gets the contents of the buffer and makes call to actions@suburl. Added actions@suburl. This function specifically performs a substitution of text in a buffer line and replaces it with a hyperlink, formatted as markdown.
This commit is contained in:
parent
dbebdde8c3
commit
dd0f25ffa1
|
|
@ -1,4 +1,5 @@
|
||||||
local gcm = require'presser.context_manager'
|
local gcm = require'presser.context_manager'
|
||||||
|
--local actions = require'presser.actions'
|
||||||
local utils = require'presser.utils'
|
local utils = require'presser.utils'
|
||||||
|
|
||||||
local a = vim.api
|
local a = vim.api
|
||||||
|
|
@ -59,6 +60,34 @@ actions.execute = function ()
|
||||||
a.nvim_exec( cmd, false )
|
a.nvim_exec( cmd, false )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
actions.hyperlink_exec = function ()
|
||||||
|
local url = utils.clean_buf(read_buffer()[1])
|
||||||
|
actions.close()
|
||||||
|
|
||||||
|
if url == "" then return nil end
|
||||||
|
|
||||||
|
local _, cur_start, _, cur_end = utils.get_selection()
|
||||||
|
local line = a.nvim_get_current_line()
|
||||||
|
if line == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local row, col = unpack(a.nvim_win_get_cursor(0))
|
||||||
|
if cur_start == -1 then
|
||||||
|
cur_start, cur_end = unpack(utils.subslice(line .. " ", col))
|
||||||
|
end
|
||||||
|
|
||||||
|
actions.suburl( line, row, url, cur_start, cur_end )
|
||||||
|
end
|
||||||
|
|
||||||
|
actions.suburl = function (line, row, url, cur_start, cur_end)
|
||||||
|
local prefix = string.sub(line, 1, cur_start) -- the first part up to selection
|
||||||
|
local suffix = string.sub(line, cur_end + 1, line:len()) -- the last part after selection
|
||||||
|
local infix = "[" .. utils.clean_buf(string.sub(line, cur_start, cur_end)) .. "]" .. "(" .. url .. ")"
|
||||||
|
|
||||||
|
a.nvim_buf_set_lines( 0, row-1, row, false, { prefix .. infix .. suffix } )
|
||||||
|
end
|
||||||
|
|
||||||
actions.buf_put_curser_at = function ( label )
|
actions.buf_put_curser_at = function ( label )
|
||||||
for _, ctx_obj in pairs( vim.g.presser_buf_ctx ) do
|
for _, ctx_obj in pairs( vim.g.presser_buf_ctx ) do
|
||||||
for _, record in pairs( ctx_obj ) do
|
for _, record in pairs( ctx_obj ) do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user