File tree 3 files changed +22
-4
lines changed
3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -319,10 +319,13 @@ return {
319
319
args = { true },
320
320
opts = { desc = ' org timestamp (inactive)' , help_desc = ' Insert/Update inactive date under cursor' },
321
321
}),
322
- org_insert_link = m .action (
323
- ' org_mappings.insert_link' ,
324
- { opts = { desc = ' org insert link' , help_desc = ' Insert a hyperlink' } }
325
- ),
322
+ org_insert_link = m .action (' org_mappings.insert_link' , {
323
+ modes = { ' n' , ' x' },
324
+ opts = {
325
+ desc = ' org insert link' ,
326
+ help_desc = ' Insert or Update a hyperlink under cursor. Visual selection used as description' ,
327
+ },
328
+ }),
326
329
org_store_link = m .action (
327
330
' org_mappings.store_link' ,
328
331
{ opts = { desc = ' org store link' , help_desc = ' Store link to current headline' } }
Original file line number Diff line number Diff line change @@ -108,6 +108,10 @@ function OrgLinks:insert_link(link_location, desc)
108
108
link_location = (' id:%s' ):format (selected_link .url :get_path ())
109
109
end
110
110
111
+ if not desc and vim .fn .mode () == ' v' then
112
+ desc = utils .get_visual_selection ()
113
+ end
114
+
111
115
return Input .open (' Description: ' , desc or ' ' ):next (function (link_description )
112
116
if not link_description then
113
117
return false
@@ -128,6 +132,12 @@ function OrgLinks:insert_link(link_location, desc)
128
132
insert_from = position .from - 1
129
133
insert_to = position .to + 1
130
134
target_col = target_col + position .from
135
+ elseif vim .fn .mode () == ' v' then
136
+ local start_pos = vim .fn .getpos (' v' )
137
+ local end_pos = vim .fn .getpos (' .' )
138
+ insert_from = start_pos [3 ] - 1
139
+ insert_to = end_pos [3 ] + 1
140
+ target_col = target_col + start_pos [3 ]
131
141
else
132
142
local colnr = vim .fn .col (' .' )
133
143
insert_from = colnr
Original file line number Diff line number Diff line change @@ -628,4 +628,9 @@ function utils.goto_headline(headline)
628
628
vim .cmd ([[ normal! zv]] )
629
629
end
630
630
631
+ --- @return string
632
+ function utils .get_visual_selection ()
633
+ return table.concat (vim .fn .getregion (vim .fn .getpos (' v' ), vim .fn .getpos (' .' )), ' \n ' )
634
+ end
635
+
631
636
return utils
You can’t perform that action at this time.
0 commit comments