forked from mirror/codesnap.nvim
[Feat] use code lines instead of raw string
This commit is contained in:
parent
7a580d2106
commit
be2992276e
3 changed files with 13 additions and 6 deletions
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue