mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 08:01:13 +01:00
Fix: text hightlight on select all and copy
This commit is contained in:
@@ -16,13 +16,11 @@ return {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local path = node:get_id()
|
local path = node:get_id()
|
||||||
|
|
||||||
-- If the node is a directory, just toggle expand/collapse
|
-- If the node is a directory, just toggle expand/collapse
|
||||||
if node.type == 'directory' then
|
if node.type == 'directory' then
|
||||||
state.commands.toggle_node(state, node)
|
state.commands.toggle_node(state, node)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- --- File handling starts here ---
|
-- --- File handling starts here ---
|
||||||
-- Reuse already open buffer in any tab safely
|
-- Reuse already open buffer in any tab safely
|
||||||
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||||
@@ -48,7 +46,6 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Reuse empty buffer in current tab
|
-- Reuse empty buffer in current tab
|
||||||
local wins = vim.api.nvim_tabpage_list_wins(0)
|
local wins = vim.api.nvim_tabpage_list_wins(0)
|
||||||
local empty_buf = nil
|
local empty_buf = nil
|
||||||
@@ -67,13 +64,11 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if empty_buf then
|
if empty_buf then
|
||||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||||
else
|
else
|
||||||
vim.cmd('tabnew ' .. vim.fn.fnameescape(path))
|
vim.cmd('tabnew ' .. vim.fn.fnameescape(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Always close Neo-tree window if open
|
-- Always close Neo-tree window if open
|
||||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||||
if vim.api.nvim_win_is_valid(win) then
|
if vim.api.nvim_win_is_valid(win) then
|
||||||
@@ -84,7 +79,6 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Smart_open_split for split windows
|
-- Smart_open_split for split windows
|
||||||
local function smart_open_split(state, direction)
|
local function smart_open_split(state, direction)
|
||||||
local node = state.tree:get_node()
|
local node = state.tree:get_node()
|
||||||
@@ -97,7 +91,6 @@ return {
|
|||||||
state.commands.toggle_node(state, node)
|
state.commands.toggle_node(state, node)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if file is open in another tab
|
-- Check if file is open in another tab
|
||||||
local open_tab, open_win
|
local open_tab, open_win
|
||||||
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||||
@@ -113,7 +106,6 @@ return {
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if open_tab then
|
if open_tab then
|
||||||
local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2)
|
local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2)
|
||||||
if choice ~= 1 then
|
if choice ~= 1 then
|
||||||
@@ -124,7 +116,6 @@ return {
|
|||||||
end
|
end
|
||||||
-- Else user chose Yes → continue to open split in current tab
|
-- Else user chose Yes → continue to open split in current tab
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Open split in current tab
|
-- Open split in current tab
|
||||||
if direction == 'v' then
|
if direction == 'v' then
|
||||||
state.commands.open_vsplit(state)
|
state.commands.open_vsplit(state)
|
||||||
@@ -140,7 +131,6 @@ return {
|
|||||||
|
|
||||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
require('neo-tree').setup {
|
require('neo-tree').setup {
|
||||||
close_if_last_window = true,
|
close_if_last_window = true,
|
||||||
popup_border_style = 'rounded',
|
popup_border_style = 'rounded',
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Enable telescope fzf native, if installed
|
-- Enable telescope fzf native, if installed
|
||||||
pcall(require('telescope').load_extension, 'fzf')
|
pcall(require('telescope').load_extension, 'fzf')
|
||||||
|
|
||||||
@@ -191,7 +190,6 @@ return {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
end, { desc = 'Switch to Open Buffers' })
|
end, { desc = 'Switch to Open Buffers' })
|
||||||
|
|
||||||
-- Telescope live_grep in git root
|
-- Telescope live_grep in git root
|
||||||
-- Function to find the git root directory based on the current buffer's path
|
-- Function to find the git root directory based on the current buffer's path
|
||||||
local function find_git_root()
|
local function find_git_root()
|
||||||
@@ -206,7 +204,6 @@ return {
|
|||||||
-- Extract the directory from the current file's path
|
-- Extract the directory from the current file's path
|
||||||
current_dir = vim.fn.fnamemodify(current_file, ':h')
|
current_dir = vim.fn.fnamemodify(current_file, ':h')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Find the Git root directory from the current file's path
|
-- Find the Git root directory from the current file's path
|
||||||
local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1]
|
local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1]
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
@@ -215,7 +212,6 @@ return {
|
|||||||
end
|
end
|
||||||
return git_root
|
return git_root
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Custom live_grep function to search in git root
|
-- Custom live_grep function to search in git root
|
||||||
local function live_grep_git_root()
|
local function live_grep_git_root()
|
||||||
local git_root = find_git_root()
|
local git_root = find_git_root()
|
||||||
@@ -225,9 +221,7 @@ return {
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
|
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
|
||||||
|
|
||||||
-- See `:help telescope.builtin`
|
-- See `:help telescope.builtin`
|
||||||
vim.keymap.set('n', '<leader>/', function()
|
vim.keymap.set('n', '<leader>/', function()
|
||||||
-- You can pass additional configuration to telescope to change theme, layout, etc.
|
-- You can pass additional configuration to telescope to change theme, layout, etc.
|
||||||
@@ -236,7 +230,6 @@ return {
|
|||||||
previewer = false,
|
previewer = false,
|
||||||
})
|
})
|
||||||
end, { desc = '[/] Fuzzily search in current buffer' })
|
end, { desc = '[/] Fuzzily search in current buffer' })
|
||||||
|
|
||||||
local function telescope_live_grep_open_files()
|
local function telescope_live_grep_open_files()
|
||||||
require('telescope.builtin').live_grep {
|
require('telescope.builtin').live_grep {
|
||||||
grep_open_files = true,
|
grep_open_files = true,
|
||||||
|
|||||||
@@ -139,11 +139,27 @@ vim.keymap.set('n', '<leader>ll', 'ggVG', { desc = 'Select all' })
|
|||||||
vim.keymap.set('n', '<leader>lY', function()
|
vim.keymap.set('n', '<leader>lY', function()
|
||||||
-- Get all lines from the buffer
|
-- Get all lines from the buffer
|
||||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||||
-- Join them without adding an extra newline
|
|
||||||
local content = table.concat(lines, '\n')
|
local content = table.concat(lines, '\n')
|
||||||
-- Set to system clipboard
|
-- Set to system clipboard
|
||||||
vim.fn.setreg('+', content)
|
vim.fn.setreg('+', content)
|
||||||
vim.fn.setreg('*', content)
|
vim.fn.setreg('*', content)
|
||||||
|
-- Highlight the full buffer
|
||||||
|
local ns = vim.api.nvim_create_namespace 'custom_yank_highlight'
|
||||||
|
local hl_group = vim.g.highlightedyank_highlight_group or 'IncSearch'
|
||||||
|
local end_row = #lines - 1
|
||||||
|
local end_col = #lines[#lines]
|
||||||
|
vim.highlight.range(
|
||||||
|
0, -- bufnr
|
||||||
|
ns,
|
||||||
|
hl_group,
|
||||||
|
{ 0, 0 }, -- start at beginning
|
||||||
|
{ end_row, end_col }, -- end at last line's end
|
||||||
|
{ inclusive = true }
|
||||||
|
)
|
||||||
|
-- Clear highlight after delay
|
||||||
|
vim.defer_fn(function()
|
||||||
|
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
|
||||||
|
end, 200)
|
||||||
-- Notify
|
-- Notify
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.notify('Copied all to clipboard', vim.log.levels.INFO)
|
vim.notify('Copied all to clipboard', vim.log.levels.INFO)
|
||||||
|
|||||||
Reference in New Issue
Block a user