refactor: use modern option setter/getter methods
This commit is contained in:
parent
66e4990240
commit
80dadc9c46
|
@ -306,15 +306,15 @@ setmetatable(M, {
|
|||
start_in_insert = start_in_insert,
|
||||
}
|
||||
for option, value in pairs(config.win_options) do
|
||||
vim.api.nvim_win_set_option(winid, option, value)
|
||||
vim.wo[winid][option] = value
|
||||
end
|
||||
local bufnr = vim.api.nvim_win_get_buf(winid)
|
||||
|
||||
-- Finish setting up the buffer
|
||||
vim.api.nvim_buf_set_option(bufnr, "swapfile", false)
|
||||
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
|
||||
vim.bo[bufnr].swapfile = false
|
||||
vim.bo[bufnr].bufhidden = "wipe"
|
||||
for k, v in pairs(config.buf_options) do
|
||||
vim.api.nvim_buf_set_option(bufnr, k, v)
|
||||
vim.bo[bufnr][k] = v
|
||||
end
|
||||
|
||||
map_util.create_plug_maps(bufnr, keymaps)
|
||||
|
@ -326,7 +326,7 @@ setmetatable(M, {
|
|||
vim.keymap.set("i", "<Esc>", M.close, { buffer = bufnr })
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_option(bufnr, "filetype", "DressingInput")
|
||||
vim.bo[bufnr].filetype = "DressingInput"
|
||||
local default = string.gsub(opts.default or "", "\n", " ")
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, { default })
|
||||
if vim.fn.has("nvim-0.9") == 0 then
|
||||
|
@ -356,8 +356,8 @@ setmetatable(M, {
|
|||
-- Disable mini.nvim completion if installed
|
||||
vim.api.nvim_buf_set_var(bufnr, "minicompletion_disable", true)
|
||||
if opts.completion then
|
||||
vim.api.nvim_buf_set_option(bufnr, "completefunc", "v:lua.dressing_input_complete")
|
||||
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.dressing_input_complete")
|
||||
vim.bo[bufnr].completefunc = "v:lua.dressing_input_complete"
|
||||
vim.bo[bufnr].omnifunc = "v:lua.dressing_input_complete"
|
||||
-- Only set up <Tab> user completion if cmp is not active
|
||||
if not has_cmp or not pcall(require, "cmp_omni") then
|
||||
vim.keymap.set("i", "<Tab>", M.trigger_completion, { buffer = bufnr, expr = true })
|
||||
|
|
|
@ -40,10 +40,10 @@ M.select = function(config, items, opts, on_choice)
|
|||
_callback = on_choice
|
||||
_items = items
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_option(bufnr, "swapfile", false)
|
||||
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
|
||||
vim.bo[bufnr].swapfile = false
|
||||
vim.bo[bufnr].bufhidden = "wipe"
|
||||
for k, v in pairs(config.buf_options) do
|
||||
vim.api.nvim_buf_set_option(bufnr, k, v)
|
||||
vim.bo[bufnr][k] = v
|
||||
end
|
||||
local lines = {}
|
||||
local max_width = 1
|
||||
|
@ -53,7 +53,7 @@ M.select = function(config, items, opts, on_choice)
|
|||
table.insert(lines, line)
|
||||
end
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
vim.bo[bufnr].modifiable = false
|
||||
local width = util.calculate_width(config.relative, max_width, config, 0)
|
||||
local height = util.calculate_height(config.relative, #lines, config, 0)
|
||||
local row = util.calculate_row(config.relative, height, 0)
|
||||
|
@ -75,12 +75,12 @@ M.select = function(config, items, opts, on_choice)
|
|||
end
|
||||
winopt = config.override(winopt) or winopt
|
||||
local winid = vim.api.nvim_open_win(bufnr, true, winopt)
|
||||
vim.api.nvim_win_set_option(winid, "cursorline", true)
|
||||
pcall(vim.api.nvim_win_set_option, winid, "cursorlineopt", "both")
|
||||
vim.wo[winid].cursorline = true
|
||||
vim.wo[winid].cursorlineopt = "both"
|
||||
for option, value in pairs(config.win_options) do
|
||||
vim.api.nvim_win_set_option(winid, option, value)
|
||||
vim.wo[winid][option] = value
|
||||
end
|
||||
vim.api.nvim_buf_set_option(bufnr, "filetype", "DressingSelect")
|
||||
vim.bo[bufnr].filetype = "DressingSelect"
|
||||
if vim.fn.has("nvim-0.9") == 0 then
|
||||
util.add_title_to_win(winid, opts.prompt)
|
||||
end
|
||||
|
|
|
@ -136,12 +136,8 @@ M.add_title_to_win = function(winid, title, opts)
|
|||
noautocmd = true,
|
||||
})
|
||||
winid_map[winid] = title_winid
|
||||
vim.api.nvim_win_set_option(
|
||||
title_winid,
|
||||
"winblend",
|
||||
vim.api.nvim_win_get_option(winid, "winblend")
|
||||
)
|
||||
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
|
||||
vim.wo[title_winid].winblend = vim.wo[winid].winblend
|
||||
vim.bo[bufnr].bufhidden = "wipe"
|
||||
vim.cmd(string.format(
|
||||
[[
|
||||
autocmd WinClosed %d ++once lua require('dressing.util')._on_win_closed(%d)
|
||||
|
|
Loading…
Reference in New Issue