1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-14 02:35:41 +08:00

perf(prompt): disable ruler when open prompt

This commit is contained in:
wsdjeg 2023-06-27 17:39:36 +08:00
parent 7b417101c8
commit 745b3ff6d1

View File

@ -13,9 +13,8 @@ local M = {}
M.__cmp = require('spacevim.api').import('vim.compatible')
M.__vim = require('spacevim.api').import('vim')
M._keys = {
close = Key.t('<Esc>')
close = Key.t('<Esc>'),
}
M._prompt = {
@ -36,6 +35,8 @@ M._onclose = ''
M._oninputpro = ''
function M.open()
local srl = vim.o.ruler
vim.o.ruler = false
M._quit = false
M._build_prompt()
if M.__cmp.fn.empty(M._prompt.cursor_begin) == 0 then
@ -43,6 +44,7 @@ function M.open()
else
M._handle_input()
end
vim.o.ruler = srl
end
function M._c_r_mode_off(timer)
@ -57,9 +59,7 @@ function M._handle_input(...)
M._oninputpro()
end
if type(M._handle_fly) == 'function' then
M._handle_fly(M._prompt.cursor_begin
.. M._prompt.cursor_char
.. M._prompt.cursor_end)
M._handle_fly(M._prompt.cursor_begin .. M._prompt.cursor_char .. M._prompt.cursor_end)
end
M._build_prompt()
end
@ -68,13 +68,15 @@ function M._handle_input(...)
local char = M.__vim.getchar()
if M._function_key[char] ~= nil then
local ok, rst = pcall(M._function_key[char])
if not ok then print(rst) end
if not ok then
print(rst)
end
goto continue
end
if M._c_r_mode then
if char:match('^[%w":+/]$') then
local reg = '@' .. char
local paste = vim.fn.get(vim.fn.split(vim.fn.eval(reg), "\n"), 0, '')
local paste = vim.fn.get(vim.fn.split(vim.fn.eval(reg), '\n'), 0, '')
M._prompt.cursor_begin = M._prompt.cursor_begin .. paste
M._prompt.cursor_char = vim.fn.matchstr(M._prompt.cursor_end, '.$')
M._c_r_mode = false
@ -103,16 +105,24 @@ function M._handle_input(...)
end
goto continue
elseif char == Key.t('<C-w>') then
M._prompt.cursor_begin = M.__cmp.fn.substitute(M._prompt.cursor_begin, [[[^\ .*]\+\s*$]],'','g')
M._prompt.cursor_begin =
M.__cmp.fn.substitute(M._prompt.cursor_begin, [[[^\ .*]\+\s*$]], '', 'g')
M._build_prompt()
elseif char == Key.t('<C-a>') or char == Key.t('<Home>') then
M._prompt.cursor_end = M.__cmp.fn.substitute(M._prompt.cursor_begin .. M._prompt.cursor_char .. M._prompt.cursor_end, '^.', '', 'g')
M._prompt.cursor_end = M.__cmp.fn.substitute(
M._prompt.cursor_begin .. M._prompt.cursor_char .. M._prompt.cursor_end,
'^.',
'',
'g'
)
M._prompt.cursor_char = M.__cmp.matchstr(M._prompt.cursor_begin, '^.')
M._prompt.cursor_begin = ''
M._build_prompt()
goto continue
elseif char == Key.t('<C-e>') or char == Key.t('<End>') then
M._prompt.cursor_begin = M._prompt.cursor_begin .. M._prompt.cursor_char .. M._prompt.cursor_end
M._prompt.cursor_begin = M._prompt.cursor_begin
.. M._prompt.cursor_char
.. M._prompt.cursor_end
M._prompt.cursor_char = ''
M._prompt.cursor_end = ''
M._build_prompt()
@ -127,11 +137,17 @@ function M._handle_input(...)
elseif char == Key.t('<bs>') then
M._prompt.cursor_begin = vim.fn.substitute(M._prompt.cursor_begin, '.$', '', 'g')
M._build_prompt()
elseif (type(M._keys.close) == 'string' and char == M._keys.close)
or (type(M._keys.close) == 'table' and vim.fn.index(M._keys.close, char) > -1 ) then
elseif
(type(M._keys.close) == 'string' and char == M._keys.close)
or (type(M._keys.close) == 'table' and vim.fn.index(M._keys.close, char) > -1)
then
M.close()
break
elseif char == Key.t('<FocusLost>') or char == Key.t('<FocusGained>') or vim.fn.char2nr(char) == 128 then
elseif
char == Key.t('<FocusLost>')
or char == Key.t('<FocusGained>')
or vim.fn.char2nr(char) == 128
then
goto continue
else
M._prompt.cursor_begin = M._prompt.cursor_begin .. char
@ -141,15 +157,12 @@ function M._handle_input(...)
M._oninputpro()
end
if type(M._handle_fly) == 'function' then
M._handle_fly(M._prompt.cursor_begin
.. M._prompt.cursor_char
.. M._prompt.cursor_end)
M._handle_fly(M._prompt.cursor_begin .. M._prompt.cursor_char .. M._prompt.cursor_end)
end
::continue::
end
end
function M._build_prompt()
local ident = M.__cmp.fn['repeat'](' ', M.__cmp.win_screenpos(0)[2] - 1)
vim.cmd('redraw')
@ -158,7 +171,7 @@ function M._build_prompt()
{ M._prompt.cursor_begin, 'None' },
{ M._prompt.cursor_char, 'Wildmenu' },
{ M._prompt.cursor_end, 'None' },
{'_', 'Comment'}
{ '_', 'Comment' },
}, false, {})
end
@ -167,7 +180,7 @@ function M._clear_prompt()
mpt = M._prompt.mpt,
cursor_begin = '',
cursor_char = '',
cursor_end = ''
cursor_end = '',
}
end
@ -179,5 +192,4 @@ function M.close()
M._quit = true
end
return M