@@ -330,18 +330,18 @@ M.prepare_commands = function()
330
330
331
331
-- template is chosen dynamically based on mode in which the command is called
332
332
local template = M .config .template_command
333
- if params .range == 2 then
333
+ if params .range > 0 then
334
334
template = M .config .template_selection
335
- -- rewrite needs custom template
336
- if target == M . Target . rewrite then
337
- template = M .config . template_rewrite
338
- end
339
- if target == M . Target . append then
340
- template = M .config . template_append
341
- end
342
- if target == M . Target . prepend then
343
- template = M .config . template_prepend
344
- end
335
+ end
336
+ -- rewrite needs custom template
337
+ if target == M .Target . rewrite then
338
+ template = M . config . template_rewrite
339
+ end
340
+ if target == M .Target . append then
341
+ template = M . config . template_append
342
+ end
343
+ if target == M .Target . prepend then
344
+ template = M . config . template_prepend
345
345
end
346
346
if agent then
347
347
M .Prompt (params , target , agent , template , agent .cmd_prefix , whisper )
@@ -1696,52 +1696,38 @@ M.Prompt = function(params, target, agent, template, prompt, whisper, callback)
1696
1696
return
1697
1697
end
1698
1698
1699
- -- defaults to normal mode
1700
- local selection = nil
1701
- local prefix = " "
1702
- local start_line = vim .api .nvim_win_get_cursor (0 )[1 ]
1703
- local end_line = start_line
1704
-
1705
- -- handle range
1706
- if params .range == 2 then
1707
- start_line = params .line1
1708
- end_line = params .line2
1709
- local lines = vim .api .nvim_buf_get_lines (buf , start_line - 1 , end_line , false )
1710
-
1711
- local min_indent = nil
1712
- local use_tabs = false
1713
- -- measure minimal common indentation for lines with content
1714
- for i , line in ipairs (lines ) do
1715
- lines [i ] = line
1716
- -- skip whitespace only lines
1717
- if not line :match (" ^%s*$" ) then
1718
- local indent = line :match (" ^%s*" )
1719
- -- contains tabs
1720
- if indent :match (" \t " ) then
1721
- use_tabs = true
1722
- end
1723
- if min_indent == nil or # indent < min_indent then
1724
- min_indent = # indent
1725
- end
1699
+ local start_line = params .line1
1700
+ local end_line = params .line2
1701
+ local lines = vim .api .nvim_buf_get_lines (buf , start_line - 1 , end_line , false )
1702
+
1703
+ local min_indent = nil
1704
+ local use_tabs = false
1705
+ -- measure minimal common indentation for lines with content
1706
+ for i , line in ipairs (lines ) do
1707
+ lines [i ] = line
1708
+ -- skip whitespace only lines
1709
+ if not line :match (" ^%s*$" ) then
1710
+ local indent = line :match (" ^%s*" )
1711
+ -- contains tabs
1712
+ if indent :match (" \t " ) then
1713
+ use_tabs = true
1714
+ end
1715
+ if min_indent == nil or # indent < min_indent then
1716
+ min_indent = # indent
1726
1717
end
1727
1718
end
1728
- if min_indent == nil then
1729
- min_indent = 0
1730
- end
1731
- prefix = string.rep (use_tabs and " \t " or " " , min_indent )
1732
-
1733
- for i , line in ipairs (lines ) do
1734
- lines [i ] = line :sub (min_indent + 1 )
1735
- end
1736
-
1737
- selection = table.concat (lines , " \n " )
1719
+ end
1720
+ if min_indent == nil then
1721
+ min_indent = 0
1722
+ end
1723
+ local prefix = string.rep (use_tabs and " \t " or " " , min_indent )
1738
1724
1739
- if selection == " " then
1740
- M .logger .warning (" Please select some text to rewrite" )
1741
- return
1742
- end
1725
+ for i , line in ipairs (lines ) do
1726
+ lines [i ] = line :sub (min_indent + 1 )
1743
1727
end
1744
1728
1729
+ local selection = table.concat (lines , " \n " )
1730
+
1745
1731
M ._selection_first_line = start_line
1746
1732
M ._selection_last_line = end_line
1747
1733
0 commit comments