1

Unwrapping

This commit is contained in:
Alex Yatskov 2024-04-28 11:28:38 -07:00
parent 987783e973
commit 3d60efb9f5

View File

@ -488,30 +488,38 @@ function WrapContext:unwrap(opt)
padding = ' ' padding = ' '
end end
local line = self.indent .. self.prefix .. padding local builder = Builder.new(self.indent_level, self.indent_block)
builder:update(self.prefix)
builder:update(padding)
local cursor = nil local cursor = nil
local update_param = function(param)
if param:is_active() then
cursor = builder:get_offset()
cursor.row = cursor.row + self.range.start.row
cursor.col = cursor.col + param.offset
end
builder:update(param.text)
end
for i, param in ipairs(self.params.parsed) do for i, param in ipairs(self.params.parsed) do
if param:is_active() then update_param(param)
cursor = Cursor.new(0, #line + param.offset)
end
line = line .. param.text
if i < #self.params.parsed then if i < #self.params.parsed then
line = line .. ', ' builder:update(', ')
end end
end end
line = line .. padding .. self.suffix builder:update(padding)
builder:update(self.suffix)
builder:flush()
vim.fn.setline(self.range.start.row, line) vim.fn.setline(self.range.start.row, builder.lines[1])
vim.fn.execute(string.format('%d,%dd_', self.range.start.row + 1, self.range.stop.row)) vim.fn.execute(string.format(
'%d,%dd_',
for _, param in ipairs(self.params.parsed) do self.range.start.row + 1,
if param:is_active() then self.range.stop.row
cursor.row = Cursor:get_current().row - 1 ))
end
end
if cursor then if cursor then
cursor:set_current() cursor:set_current()