mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 22:10:06 +08:00
perf(scrollbar): use vim#buffer
api
This commit is contained in:
parent
5b88660a3f
commit
4563880fee
@ -32,6 +32,14 @@
|
|||||||
" initfunc: the function which will be call after creating buffer
|
" initfunc: the function which will be call after creating buffer
|
||||||
"
|
"
|
||||||
" cmd: the ex command which will be run after the new buffer is created
|
" cmd: the ex command which will be run after the new buffer is created
|
||||||
|
"
|
||||||
|
" get_option(bufnr, name)
|
||||||
|
"
|
||||||
|
" Gets a buffer option value.
|
||||||
|
"
|
||||||
|
" set_option(buf, opt, value)
|
||||||
|
"
|
||||||
|
" Set a buffer option value.
|
||||||
|
|
||||||
|
|
||||||
let s:self = {}
|
let s:self = {}
|
||||||
|
@ -6872,6 +6872,14 @@ is a dict with following keys:
|
|||||||
|
|
||||||
cmd: the ex command which will be run after the new buffer is created
|
cmd: the ex command which will be run after the new buffer is created
|
||||||
|
|
||||||
|
get_option(bufnr, name)
|
||||||
|
|
||||||
|
Gets a buffer option value.
|
||||||
|
|
||||||
|
set_option(buf, opt, value)
|
||||||
|
|
||||||
|
Set a buffer option value.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
VIM#COMMAND *SpaceVim-api-vim-command*
|
VIM#COMMAND *SpaceVim-api-vim-command*
|
||||||
|
|
||||||
|
@ -13,38 +13,33 @@ function M.create_buf(listed, scratch)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.set_lines(bufnr, startindex, endindex, replacement)
|
function M.set_lines(bufnr, startindex, endindex, replacement)
|
||||||
if startindex < 0 then
|
if startindex < 0 then
|
||||||
startindex = #vim.buffer(bufnr) + 1 + startindex
|
startindex = #vim.buffer(bufnr) + 1 + startindex
|
||||||
|
end
|
||||||
|
if endindex < 0 then
|
||||||
|
endindex = #vim.buffer(bufnr) + 1 + endindex
|
||||||
|
end
|
||||||
|
if #replacement == endindex - startindex then
|
||||||
|
for i = startindex, endindex - 1, 1 do
|
||||||
|
vim.buffer(bufnr)[i + 1] = replacement[i - startindex]
|
||||||
end
|
end
|
||||||
if endindex < 0 then
|
else
|
||||||
endindex = #vim.buffer(bufnr) + 1 + endindex
|
if endindex < #vim.buffer(bufnr) then
|
||||||
|
for i = endindex + 1, #vim.buffer(bufnr), 1 do
|
||||||
|
replacement:add(vim.buffer(bufnr)[i])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if #replacement == endindex - startindex then
|
for i = startindex, #replacement + startindex - 1, 1 do
|
||||||
for i = startindex, endindex - 1, 1
|
if i + 1 > #vim.buffer(bufnr) then
|
||||||
do
|
vim.buffer(bufnr):insert(replacement[i - startindex])
|
||||||
vim.buffer(bufnr)[i + 1] = replacement[i - startindex]
|
else
|
||||||
end
|
vim.buffer(bufnr)[i + 1] = replacement[i - startindex]
|
||||||
else
|
end
|
||||||
if endindex < #vim.buffer(bufnr) then
|
|
||||||
for i = endindex + 1, #vim.buffer(bufnr), 1
|
|
||||||
do
|
|
||||||
replacement:add(vim.buffer(bufnr)[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i = startindex, #replacement + startindex - 1, 1
|
|
||||||
do
|
|
||||||
if i + 1 > #vim.buffer(bufnr) then
|
|
||||||
vim.buffer(bufnr):insert(replacement[i - startindex])
|
|
||||||
else
|
|
||||||
vim.buffer(bufnr)[i + 1] = replacement[i - startindex]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i = #replacement + startindex + 1, #vim.buffer(bufnr), 1
|
|
||||||
do
|
|
||||||
vim.buffer(bufnr)[#replacement + startindex + 1] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
for i = #replacement + startindex + 1, #vim.buffer(bufnr), 1 do
|
||||||
|
vim.buffer(bufnr)[#replacement + startindex + 1] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.listed_buffers() -- {{{
|
function M.listed_buffers() -- {{{
|
||||||
@ -53,24 +48,37 @@ end
|
|||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
function M.resize(size, ...)
|
function M.resize(size, ...)
|
||||||
local arg = {...}
|
local arg = { ... }
|
||||||
local cmd = arg[1] or 'vertical'
|
local cmd = arg[1] or 'vertical'
|
||||||
vim.cmd(cmd .. ' resize ' .. size)
|
vim.cmd(cmd .. ' resize ' .. size)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.open_pos(cmd, filename, line, col)
|
function M.open_pos(cmd, filename, line, col)
|
||||||
vim.cmd('silent ' .. cmd .. ' ' .. filename)
|
vim.cmd('silent ' .. cmd .. ' ' .. filename)
|
||||||
vim.fn.cursor(line, col)
|
vim.fn.cursor(line, col)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr number the buffer number
|
---@param bufnr number the buffer number
|
||||||
---@param opt string option name
|
---@param opt string option name
|
||||||
---@param value any option value
|
---@param value any option value
|
||||||
function M.set_option(bufnr, opt, value)
|
function M.set_option(bufnr, opt, value)
|
||||||
|
if vim.api.nvim_set_option_value then
|
||||||
|
return vim.api.nvim_set_option_value(opt, value, {
|
||||||
|
buf = bufnr
|
||||||
|
})
|
||||||
|
end
|
||||||
|
if vim.api.nvim_buf_set_option then
|
||||||
|
return vim.api.nvim_buf_set_option(bufnr, opt, value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_option(bufnr, name)
|
||||||
|
if vim.api.nvim_get_option_value then
|
||||||
|
return vim.api.nvim_get_option_value(name, { buf = bufnr })
|
||||||
|
end
|
||||||
|
if vim.api.nvim_buf_get_option then
|
||||||
|
return vim.api.nvim_buf_get_option(bufnr, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local win = require('spacevim.api.vim.window')
|
local win = require('spacevim.api.vim.window')
|
||||||
|
local buffer = require('spacevim.api.vim.buffer')
|
||||||
|
|
||||||
local default_conf = {
|
local default_conf = {
|
||||||
max_size = 10,
|
max_size = 10,
|
||||||
@ -75,7 +76,7 @@ local function create_scrollbar_buffer(size, lines)
|
|||||||
if not vim.api.nvim_buf_is_valid(scrollbar_bufnr) then
|
if not vim.api.nvim_buf_is_valid(scrollbar_bufnr) then
|
||||||
scrollbar_bufnr = vim.api.nvim_create_buf(false, true)
|
scrollbar_bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
end
|
end
|
||||||
vim.api.nvim_buf_set_option(scrollbar_bufnr, 'buftype', 'nofile')
|
buffer.set_option(scrollbar_bufnr, 'buftype', 'nofile')
|
||||||
vim.api.nvim_buf_set_lines(scrollbar_bufnr, 0, -1, false, lines)
|
vim.api.nvim_buf_set_lines(scrollbar_bufnr, 0, -1, false, lines)
|
||||||
return scrollbar_bufnr
|
return scrollbar_bufnr
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user