Skip to content

Commit

Permalink
transform selection
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAppSec committed Sep 6, 2024
1 parent 0ae0bd0 commit c40334a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lua/hacker-helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,23 @@ M.setup = function(user_config)
end
-- Function to handle encoding/decoding based on selection
M.transform_selected_text = function(type, mode)
-- Capture the selection
local start_pos = vim.fn.getpos("'<")
local end_pos = vim.fn.getpos("'>")
local start_line, start_col = start_pos[2], start_pos[3] - 1 -- Convert to 0-based index
local end_line, end_col = end_pos[2], end_pos[3] - 1 -- Convert to 0-based index

-- Get selected lines
local start_line = start_pos[2]
local start_col = start_pos[3] - 1 -- Convert to 0-based index

local end_line = end_pos[2]
local end_col = end_pos[3] - 1 -- Convert to 0-based index

-- Adjust for visual line selection
if vim.fn.mode() == "V" then
start_col = 0
end_col = -1
end

-- Get the selected lines
local lines = vim.fn.getline(start_line, end_line)

-- If no lines were selected, return early
Expand All @@ -103,9 +114,8 @@ M.transform_selected_text = function(type, mode)
return
end

-- Handle full line selection
-- Full-line selection: Transform the entire lines
if start_col == 0 and end_col == -1 then
-- Full-line transformation
if type == "url" then
lines = M.transform_lines(lines, mode, "url")
elseif type == "base64" then
Expand All @@ -114,7 +124,7 @@ M.transform_selected_text = function(type, mode)
-- Replace all selected lines with the transformed lines
vim.fn.setline(start_line, lines)
else
-- Handle partial selection within a single line
-- Partial selection within a single line
if lines and lines[1] then
local line = lines[1]

Expand Down

0 comments on commit c40334a

Please sign in to comment.