Skip to content

Commit 7bc8a47

Browse files
committed
map
1 parent c664276 commit 7bc8a47

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lua/fittencode/base/shadow_text_model.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,22 @@ function ShadowTextModel:get_text(encoding, range)
219219
return table.concat(result_lines, self.eol)
220220
end
221221

222+
---@param src_encoding lsp.PositionEncodingKind
223+
---@param dest_encoding lsp.PositionEncodingKind
224+
---@param position FittenCode.Position
225+
---@return FittenCode.Position
226+
function ShadowTextModel:map(src_encoding, dest_encoding, position)
227+
local row = position.row
228+
local col = position.col
229+
local pi = self:_get_layout(row)
230+
if src_encoding == 'utf-8' then
231+
col = Fn.byte_to_utfindex(pi, dest_encoding, position.col + 1)[1] - 1
232+
else
233+
col = Fn.utf_to_byteindex(pi, dest_encoding, position.col + 1)[1] - 1
234+
end
235+
return Position.of(row, col)
236+
end
237+
222238
-- function M.normalize_range(buf, range)
223239
-- if range.start.col == 2147483647 then
224240
-- range.start.col = -1

0 commit comments

Comments
 (0)