File tree Expand file tree Collapse file tree 5 files changed +50
-1
lines changed Expand file tree Collapse file tree 5 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ require"gitlinker".setup()
7070-  ` <leader>gy `  for normal and visual mode
7171
7272When used, it will copy the generated url to your clipboard and print it in
73- ` :messages ` .
73+ ` :messages `  with highlight of the selected region .
7474
7575-  In normal mode, it will add the current line number to the url
7676-  In visual mode , it will add the line range of the visual selection to the url
@@ -126,6 +126,9 @@ require"gitlinker".setup({
126126    action_callback  =  require " gitlinker.actions" copy_to_clipboard ,
127127    --  print the url after performing the action
128128    print_url  =  true ,
129+     --  highlights the linked line(s) by the time in ms
130+     --  disable highlight by setting a value equal or less than 0
131+     highlight_duration  =  100 ,
129132  },
130133  callbacks  =  {
131134        [" github.com" =  require " gitlinker.hosts" get_github_type_url ,
Original file line number Diff line number Diff line change @@ -124,6 +124,9 @@ Here’s all the options with their defaults:
124124      action_callback = require"gitlinker.actions".copy_to_clipboard, 
125125      -- print the url after performing the action 
126126      print_url = true, 
127+       -- highlights the linked line(s) by the time in ms 
128+       -- disable highlight by setting a value equal or less than 0 
129+       highlight_duration = 100, 
127130      -- mapping to call url generation 
128131      mappings = "<leader>gy" 
129132    }, 
Original file line number Diff line number Diff line change @@ -124,6 +124,11 @@ function M.get_buf_range_url(mode, user_opts)
124124
125125  local  url  =  matching_callback (url_data )
126126
127+   if  user_opts .highlight_duration  >=  0  then 
128+     buffer .highlight_range (url_data )
129+     vim .defer_fn (buffer .clear_highlights , user_opts .highlight_duration )
130+   end 
131+ 
127132  if  user_opts .action_callback  then 
128133    user_opts .action_callback (url )
129134  end 
Original file line number Diff line number Diff line change @@ -24,4 +24,36 @@ function M.get_range(mode, add_current_line_on_normal_mode)
2424  return  { lstart  =  lstart , lend  =  lend  }
2525end 
2626
27+ --[[ 
28+ Highlights the text selected by the specified range. 
29+ ]] 
30+ M .highlight_range  =  function (range )
31+   local  namespace  =  vim .api .nvim_create_namespace (" NvimGitLinker" 
32+   local  lstart , lend  =  range .lstart , range .lend 
33+   if  lend  and  lend  <  lstart  then 
34+     lstart , lend  =  lend , lstart 
35+   end 
36+   local  pos1  =  { lstart  -  1 , 1  }
37+   local  pos2  =  { (lend  or  lstart ) -  1 , vim .fn .col (" $" 
38+   vim .highlight .range (
39+     0 ,
40+     namespace ,
41+     " NvimGitLinkerHighlightTextObject" 
42+     pos1 ,
43+     pos2 ,
44+     { inclusive  =  true  }
45+   )
46+   --  Force the screen to highlight the text immediately
47+   vim .cmd (" redraw" 
48+ end 
49+ 
50+ --[[ 
51+ Clears the gitlinker highlights for the buffer. 
52+ ]] 
53+ M .clear_highlights  =  function ()
54+   local  namespace  =  vim .api .nvim_create_namespace (" NvimGitLinker" 
55+   vim .api .nvim_buf_clear_namespace (0 , namespace , 0 , - 1 )
56+   --  Force the screen to clear the highlight immediately
57+   vim .cmd (" redraw" 
58+ end 
2759return  M 
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ local defaults = {
55  add_current_line_on_normal_mode  =  true , --  if true adds the line nr in the url for normal mode
66  action_callback  =  require (" gitlinker.actions" copy_to_clipboard , --  callback for what to do with the url
77  print_url  =  true , --  print the url after action
8+   highlight_duration  =  100 , --  highlight the linked region
89}
910
1011local  opts 
@@ -14,6 +15,11 @@ function M.setup(user_opts)
1415    opts  =  vim .tbl_deep_extend (" force" defaults )
1516  end 
1617  opts  =  vim .tbl_deep_extend (" force" opts , user_opts  or  {})
18+ 
19+   --  Configure highlight group
20+   if  user_opts .highlight_duration  >=  0  then 
21+     vim .api .nvim_set_hl (0 , " NvimGitLinkerHighlightTextObject" link  =  " Search" 
22+   end 
1723end 
1824
1925function  M .get ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments