Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
138 lines
3.3 KiB
Lua
138 lines
3.3 KiB
Lua
local api = vim.api
|
|
local Buffer = require('if_lua_compat.buffer')
|
|
|
|
--- Wrapper to interact with windows
|
|
--- @class Window
|
|
|
|
local Window
|
|
|
|
local win_methods = {
|
|
--- @param self Window
|
|
--- @return boolean
|
|
isvalid = function(self)
|
|
return api.nvim_win_is_valid(self._winnr)
|
|
end,
|
|
|
|
--- @param self Window
|
|
--- @return Window|nil
|
|
next = function(self)
|
|
local winnr = self._winnr
|
|
local windows = api.nvim_tabpage_list_wins(api.nvim_win_get_tabpage(winnr))
|
|
local next_win
|
|
for k, v in ipairs(windows) do
|
|
if v == winnr then
|
|
next_win = k + 1
|
|
break
|
|
end
|
|
end
|
|
if next_win and windows[next_win] then
|
|
return Window(next_win)
|
|
end
|
|
return nil
|
|
end,
|
|
|
|
--- @param self Window
|
|
--- @return Window|nil
|
|
previous = function(self)
|
|
local winnr = self._winnr
|
|
local windows = api.nvim_tabpage_list_wins(api.nvim_win_get_tabpage(winnr))
|
|
local prev_win
|
|
for k, v in ipairs(windows) do
|
|
if v == winnr then
|
|
prev_win = k - 1
|
|
break
|
|
end
|
|
end
|
|
if prev_win and windows[prev_win] then
|
|
return Window(prev_win)
|
|
end
|
|
return nil
|
|
end,
|
|
}
|
|
|
|
local win_getters = {
|
|
--- @param winnr number
|
|
--- @return Buffer
|
|
buffer = function(winnr)
|
|
return Buffer(api.nvim_win_get_buf(winnr))
|
|
end,
|
|
|
|
--- @param winnr number
|
|
--- @return number
|
|
line = function(winnr)
|
|
return api.nvim_win_get_cursor(winnr)[1]
|
|
end,
|
|
|
|
--- @param winnr number
|
|
--- @return number
|
|
col = function(winnr)
|
|
return api.nvim_win_get_cursor(winnr)[2] + 1
|
|
end,
|
|
|
|
--- @param winnr number
|
|
--- @return number
|
|
width = api.nvim_win_get_width,
|
|
|
|
--- @param winnr number
|
|
--- @return number
|
|
height = api.nvim_win_get_height,
|
|
}
|
|
|
|
local win_setters = {
|
|
--- @param winnr number
|
|
--- @param line number
|
|
line = function(winnr, line)
|
|
api.nvim_win_set_cursor(winnr, {line, 0})
|
|
end,
|
|
|
|
--- @param winnr number
|
|
--- @param col number
|
|
col = function(winnr, col)
|
|
api.nvim_win_set_cursor(winnr, {api.nvim_win_get_cursor(winnr)[1], col - 1})
|
|
end,
|
|
|
|
--- @param winnr number
|
|
--- @param width number
|
|
width = api.nvim_win_set_width,
|
|
|
|
--- @param winnr number
|
|
--- @param height number
|
|
height = api.nvim_win_set_height,
|
|
}
|
|
|
|
local win_mt = {
|
|
_vim_type = 'window',
|
|
__index = function(tbl, key)
|
|
if win_methods[key] then return win_methods[key] end
|
|
if win_getters[key] then return win_getters[key](tbl._winnr) end
|
|
end,
|
|
__newindex = function(tbl, key, value)
|
|
if win_setters[key] then return win_setters[key](tbl._winnr, value)
|
|
else error(('Invalid window property: %s'):format(key))
|
|
end
|
|
end,
|
|
__call = function(tbl)
|
|
api.nvim_set_current_win(tbl._winnr)
|
|
end,
|
|
}
|
|
|
|
--- @param arg ?any
|
|
--- @return Window|nil
|
|
function Window(arg)
|
|
local windows = api.nvim_tabpage_list_wins(0)
|
|
local winnr
|
|
|
|
if not arg then
|
|
winnr = api.nvim_get_current_win()
|
|
elseif type(arg) == 'number' then
|
|
if not windows[arg] then return nil end
|
|
winnr = windows[arg]
|
|
else
|
|
winnr = windows[1]
|
|
end
|
|
|
|
return setmetatable({_winnr = winnr}, win_mt)
|
|
end
|
|
|
|
return Window
|