Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/opencode/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function M.build_inline_selection_text(range)

local fence = string.rep('`', n)
local filetype = vim.bo[buf].filetype or ''
local code = current_selection.text:gsub('^%s+', ''):gsub('%s+$', '')
local code = current_selection.text:gsub('^%s+\r?\n', ''):gsub('%s+$', '')
local text ---@type string
if file then
text = string.format('**`%s`**\n\n%s%s\n%s\n%s', file.path, fence, filetype, code, fence)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/context_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ describe('build_inline_selection_text', function()
return false
end
BaseContext.get_current_selection = function()
return { text = 'function foo()\n return 42\nend', lines = '10, 12' }
return { text = ' function foo()\n return 42\nend', lines = '10, 12' }
end
BaseContext.get_current_file_for_selection = function()
return nil
Expand All @@ -1225,7 +1225,7 @@ describe('build_inline_selection_text', function()
assert.is_not_nil(text)
assert.is_nil(text:match('%*%*`'))
assert.is_not_nil(text:match('```lua'))
assert.is_not_nil(text:match('function foo%(%)'))
assert.is_not_nil(text:match(' function foo%(%)'))
assert.is_not_nil(text:match('```$'))

util.is_buf_a_file = original_is_buf_a_file
Expand Down
Loading