Skip to content

Commit

Permalink
[Feat] use code lines instead of raw string
Browse files Browse the repository at this point in the history
  • Loading branch information
mistricky committed May 4, 2024
1 parent c0b27cb commit 7605b6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lua/codesnap/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function highlight_module.create_highlight_selector_window(cb_name, code)
local col = vim.fn.winwidth(0) / 2 - width / 2
local bufnr = vim.api.nvim_create_buf(false, true)

vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, string_utils.split(code, "\n"))
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, code)

local window_id = vim.api.nvim_open_win(bufnr, false, {
relative = "editor",
width = width,
Expand Down
8 changes: 6 additions & 2 deletions lua/codesnap/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local static = require("codesnap.static")
local visual_utils = require("codesnap.utils.visual")
local table_utils = require("codesnap.utils.table")
local string_utils = require("codesnap.utils.string")
local config_module = require("codesnap.config")
Expand Down Expand Up @@ -53,13 +54,16 @@ end
function main.highlight_mode_copy_into_clipboard(extension)
main.highlight_mode_config = config_module.get_config(extension)

highlight_module.create_highlight_selector_window("copy_into_clipboard_with_config", main.highlight_mode_config.code)
highlight_module.create_highlight_selector_window(
"copy_into_clipboard_with_config",
visual_utils.get_selected_lines()
)
end

function main.highlight_mode_save_snapshot(extension)
main.highlight_mode_config = config_module.get_config(extension)

highlight_module.create_highlight_selector_window("save_snapshot_with_config", main.highlight_mode_config.code)
highlight_module.create_highlight_selector_window("save_snapshot_with_config", visual_utils.get_selected_lines())
end

return main
8 changes: 5 additions & 3 deletions lua/codesnap/utils/visual.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ function visual_utils.get_end_line_number()
return vim.fn.line("'>")
end

function visual_utils.get_selected_text()
local selected_text = vim.fn.getline("'<", "'>")
function visual_utils.get_selected_lines()
return vim.fn.getline("'<", "'>")
end

return table.concat(selected_text, "\n")
function visual_utils.get_selected_text()
return table.concat(visual_utils.get_selected_lines(), "\n")
end

function visual_utils.get_selected_text_realtime()
Expand Down

0 comments on commit 7605b6c

Please sign in to comment.