[Feat] use code lines instead of raw string

pull/100/head
Mist 2024-05-04 21:03:10 +08:00 committed by The Mist
parent 7a580d2106
commit be2992276e
3 changed files with 13 additions and 6 deletions

View File

@ -22,7 +22,8 @@ function highlight_module.create_highlight_selector_window(cb_name, code)
local col = vim.fn.winwidth(0) / 2 - width / 2 local col = vim.fn.winwidth(0) / 2 - width / 2
local bufnr = vim.api.nvim_create_buf(false, true) 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, { local window_id = vim.api.nvim_open_win(bufnr, false, {
relative = "editor", relative = "editor",
width = width, width = width,

View File

@ -1,4 +1,5 @@
local static = require("codesnap.static") local static = require("codesnap.static")
local visual_utils = require("codesnap.utils.visual")
local table_utils = require("codesnap.utils.table") local table_utils = require("codesnap.utils.table")
local string_utils = require("codesnap.utils.string") local string_utils = require("codesnap.utils.string")
local config_module = require("codesnap.config") local config_module = require("codesnap.config")
@ -53,13 +54,16 @@ end
function main.highlight_mode_copy_into_clipboard(extension) function main.highlight_mode_copy_into_clipboard(extension)
main.highlight_mode_config = config_module.get_config(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 end
function main.highlight_mode_save_snapshot(extension) function main.highlight_mode_save_snapshot(extension)
main.highlight_mode_config = config_module.get_config(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 end
return main return main

View File

@ -22,10 +22,12 @@ function visual_utils.get_end_line_number()
return vim.fn.line("'>") return vim.fn.line("'>")
end end
function visual_utils.get_selected_text() function visual_utils.get_selected_lines()
local selected_text = vim.fn.getline("'<", "'>") 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 end
function visual_utils.get_selected_text_realtime() function visual_utils.get_selected_text_realtime()