mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 05:50:05 +08:00
feat(flygrep): add open_iten function
This commit is contained in:
parent
fa7d5dc1be
commit
73069ba781
@ -49,6 +49,11 @@ function M.resize(size, ...)
|
|||||||
vim.cmd(cmd .. ' resize ' .. size)
|
vim.cmd(cmd .. ' resize ' .. size)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.open_pos(cmd, filename, line, col)
|
||||||
|
vim.cmd('silent ' .. cmd .. ' ' .. filename)
|
||||||
|
vim.fn.cursor(line, col)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ local mpt = require('spacevim.api').import('prompt')
|
|||||||
local hi = require('spacevim.api').import('vim.highlight')
|
local hi = require('spacevim.api').import('vim.highlight')
|
||||||
local regex = require('spacevim.api').import('vim.regex')
|
local regex = require('spacevim.api').import('vim.regex')
|
||||||
local Key = require('spacevim.api').import('vim.keys')
|
local Key = require('spacevim.api').import('vim.keys')
|
||||||
|
local buffer = require('spacevim.api').import('vim.buffer')
|
||||||
|
|
||||||
-- compatibility functions
|
-- compatibility functions
|
||||||
local jobstart = vim.fn.jobstart
|
local jobstart = vim.fn.jobstart
|
||||||
@ -48,6 +49,8 @@ local grep_expr_opt = {}
|
|||||||
local hi_id = -1
|
local hi_id = -1
|
||||||
local grep_mode = 'expr'
|
local grep_mode = 'expr'
|
||||||
local filename_pattern = [[[^:]*:\d\+:\d\+:]]
|
local filename_pattern = [[[^:]*:\d\+:\d\+:]]
|
||||||
|
local previous_able = false
|
||||||
|
local grep_history = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -64,6 +67,8 @@ local function read_histroy()
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
grep_history = read_histroy()
|
||||||
|
|
||||||
|
|
||||||
local function update_history()
|
local function update_history()
|
||||||
if vim.fn.index(grep_history, grep_expr) >= 0 then
|
if vim.fn.index(grep_history, grep_expr) >= 0 then
|
||||||
@ -120,7 +125,6 @@ local function get_search_cmd(expr)
|
|||||||
return cmd
|
return cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
local grep_history = read_histroy()
|
|
||||||
local complete_input_history_num = {0, 0}
|
local complete_input_history_num = {0, 0}
|
||||||
|
|
||||||
local function grep_stdout(id, data, event)
|
local function grep_stdout(id, data, event)
|
||||||
@ -270,6 +274,40 @@ local function previous_item()
|
|||||||
mpt._build_prompt()
|
mpt._build_prompt()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function close_preview_win()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_file_pos(line)
|
||||||
|
local filename = vim.fn.fnameescape(vim.fn.split(line, [[:\d\+:]])[1])
|
||||||
|
local linenr = vim.fn.str2nr(string.sub(vim.fn.matchstr(line, [[:\d\+:]]), 2, -2))
|
||||||
|
local colum = vim.fn.str2nr(string.sub(vim.fn.matchstr(line, [[\(:\d\+\)\@<=:\d\+:]]), 2, -2))
|
||||||
|
return filename, linenr, colum
|
||||||
|
end
|
||||||
|
|
||||||
|
local function open_item()
|
||||||
|
mpt._handle_fly = flygrep
|
||||||
|
local cursor = vim.api.nvim_win_get_cursor(flygrep_win_id)
|
||||||
|
local line = vim.api.nvim_buf_get_lines(buffer_id, cursor[1] - 1, cursor[1], false)[1]
|
||||||
|
-- print(vim.inspect(line))
|
||||||
|
if line ~= '' then
|
||||||
|
if grepid ~= 0 then
|
||||||
|
jobstop(grepid)
|
||||||
|
end
|
||||||
|
mpt._clear_prompt()
|
||||||
|
mpt._quit = 1
|
||||||
|
local filename, liner, colum = get_file_pos(line)
|
||||||
|
if previous_able then
|
||||||
|
close_preview_win()
|
||||||
|
end
|
||||||
|
previous_able = false
|
||||||
|
close_flygrep_win()
|
||||||
|
update_history()
|
||||||
|
buffer.open_pos('edit', filename, linenr, colum)
|
||||||
|
vim.cmd('noautocmd normal! :')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
mpt._function_key = {
|
mpt._function_key = {
|
||||||
[Key.t('<Tab>')] = next_item,
|
[Key.t('<Tab>')] = next_item,
|
||||||
[Key.t('<C-j>')] = next_item,
|
[Key.t('<C-j>')] = next_item,
|
||||||
@ -387,5 +425,4 @@ function M.open(argv)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user