mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 09:20:06 +08:00
fix(recordkey): fix win order
This commit is contained in:
parent
f6e07c5659
commit
a31dc92f8e
@ -14,12 +14,15 @@ local max_count = 5
|
|||||||
|
|
||||||
local keys = {}
|
local keys = {}
|
||||||
|
|
||||||
|
local winids = {}
|
||||||
|
|
||||||
local pos = 0
|
local pos = 0
|
||||||
|
|
||||||
local enabled = false
|
local enabled = false
|
||||||
local ns_is = vim.api.nvim_create_namespace('record-key')
|
local ns_is = vim.api.nvim_create_namespace('record-key')
|
||||||
|
local logger = require('spacevim.logger').derive('recordkey')
|
||||||
|
|
||||||
local function show_key(key)
|
local function show_key(key, where)
|
||||||
local save_ei = vim.o.eventignore
|
local save_ei = vim.o.eventignore
|
||||||
vim.o.eventignore = 'all'
|
vim.o.eventignore = 'all'
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
@ -28,19 +31,19 @@ local function show_key(key)
|
|||||||
local w = 8
|
local w = 8
|
||||||
|
|
||||||
if vim.fn.strdisplaywidth(key) > 8 then
|
if vim.fn.strdisplaywidth(key) > 8 then
|
||||||
w = vim.fn.strdisplaywidth(key) + 2
|
w = vim.fn.strdisplaywidth(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
local winid = vim.api.nvim_open_win(buf, false, {
|
local winid = vim.api.nvim_open_win(buf, false, {
|
||||||
relative = 'editor',
|
relative = 'editor',
|
||||||
width = w,
|
width = w,
|
||||||
height = 1,
|
height = 1,
|
||||||
row = vim.o.lines - w - 2 - pos * 3,
|
row = vim.o.lines - 5 - where * 3,
|
||||||
col = vim.o.columns - 25,
|
col = vim.o.columns - 25,
|
||||||
focusable = false,
|
focusable = false,
|
||||||
noautocmd = true,
|
noautocmd = true,
|
||||||
border = 'single',
|
border = 'single',
|
||||||
})
|
})
|
||||||
|
table.insert(winids, winid)
|
||||||
vim.fn.setbufvar(buf, '&number', 0)
|
vim.fn.setbufvar(buf, '&number', 0)
|
||||||
vim.fn.setbufvar(buf, '&relativenumber', 0)
|
vim.fn.setbufvar(buf, '&relativenumber', 0)
|
||||||
vim.fn.setbufvar(buf, '&cursorline', 0)
|
vim.fn.setbufvar(buf, '&cursorline', 0)
|
||||||
@ -58,15 +61,25 @@ local function show_key(key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function display()
|
local function display()
|
||||||
|
local save_ei = vim.o.eventignore
|
||||||
|
vim.o.eventignore = 'all'
|
||||||
|
for _, id in ipairs(winids) do
|
||||||
|
if vim.api.nvim_win_is_valid(id) then
|
||||||
|
vim.api.nvim_win_close(id, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.o.eventignore = save_ei
|
||||||
|
winids = {}
|
||||||
pos = 0
|
pos = 0
|
||||||
|
logger.debug(vim.inspect(keys))
|
||||||
if #keys > max_count then
|
if #keys > max_count then
|
||||||
for i = 1, max_count, 1 do
|
for i = 1, max_count, 1 do
|
||||||
show_key(keys[#keys - i + 1])
|
show_key(keys[#keys - i + 1], pos)
|
||||||
pos = pos + 1
|
pos = pos + 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for i = 1, #keys, 1 do
|
for i = 1, #keys, 1 do
|
||||||
show_key(keys[#keys - i + 1])
|
show_key(keys[#keys - i + 1], pos)
|
||||||
pos = pos + 1
|
pos = pos + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -85,6 +98,7 @@ local function on_key(oldkey, key)
|
|||||||
if #key == 0 then
|
if #key == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
logger.debug(' key:>' .. key .. '<')
|
||||||
table.insert(keys, vim.fn.keytrans(key))
|
table.insert(keys, vim.fn.keytrans(key))
|
||||||
vim.fn.timer_start(timeout, function()
|
vim.fn.timer_start(timeout, function()
|
||||||
if #keys > 0 then
|
if #keys > 0 then
|
||||||
|
Loading…
Reference in New Issue
Block a user