Skip to content

Commit 67c6508

Browse files
committed
fix: add_visual_selection_inline shouldn't trim indent
1 parent a40b8af commit 67c6508

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

lua/opencode/context.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function M.build_inline_selection_text(range)
196196

197197
local fence = string.rep('`', n)
198198
local filetype = vim.bo[buf].filetype or ''
199-
local code = current_selection.text:gsub('^%s+', ''):gsub('%s+$', '')
199+
local code = current_selection.text:gsub('^%s+\r?\n', ''):gsub('%s+$', '')
200200
local text ---@type string
201201
if file then
202202
text = string.format('**`%s`**\n\n%s%s\n%s\n%s', file.path, fence, filetype, code, fence)

tests/unit/context_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ describe('build_inline_selection_text', function()
12041204
return false
12051205
end
12061206
BaseContext.get_current_selection = function()
1207-
return { text = 'function foo()\n return 42\nend', lines = '10, 12' }
1207+
return { text = ' function foo()\n return 42\nend', lines = '10, 12' }
12081208
end
12091209
BaseContext.get_current_file_for_selection = function()
12101210
return nil
@@ -1225,7 +1225,7 @@ describe('build_inline_selection_text', function()
12251225
assert.is_not_nil(text)
12261226
assert.is_nil(text:match('%*%*`'))
12271227
assert.is_not_nil(text:match('```lua'))
1228-
assert.is_not_nil(text:match('function foo%(%)'))
1228+
assert.is_not_nil(text:match(' function foo%(%)'))
12291229
assert.is_not_nil(text:match('```$'))
12301230

12311231
util.is_buf_a_file = original_is_buf_a_file

0 commit comments

Comments
 (0)