Skip to content

Commit

Permalink
Merge pull request #19 from Cassin01/update
Browse files Browse the repository at this point in the history
update init
  • Loading branch information
Cassin01 authored Feb 15, 2023
2 parents 557102d + 380e6ab commit 9b52e6b
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 33 deletions.
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select() wf.txt /*select()*
15 changes: 15 additions & 0 deletions doc/wf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
==============================================================================
------------------------------------------------------------------------------
*select()*
`select`({items}, {opts}, {on_choice})
Define your wf setup.

Parameters~
{items} items
{the} options for wf
{on_choice} A callback that will be carried
Usage~
`require("wf").select(items, opts, on_choice)`


vim:tw=78:ts=8:noet:ft=help:norl:
1 change: 1 addition & 0 deletions lua/wf/builtin/which_key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ local function _get_bmap(buf, mode)
return choices
end

---@param opts? table
local function which_key(opts)
local core = function()
local buf = vim.api.nvim_get_current_buf()
Expand Down
4 changes: 2 additions & 2 deletions lua/wf/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ local function open_win(buf, height, row_offset, opts, cursor)
return vim.api.nvim_open_win(buf, cursor or false, conf)
end

local function gen_obj(row_offset, opts, cursor)
local function gen_obj(row_offset, opts, cursor, buftype)
local buf = vim.api.nvim_create_buf(false, true)
local height = vim.api.nvim_buf_line_count(buf)
local win = open_win(buf, height, row_offset, opts, cursor)
vim.api.nvim_win_set_option(win, "winhl", "Normal:WFNormal,FloatBorder:WFFloatBorder")
vim.api.nvim_win_set_option(win, "wrap", false)
vim.api.nvim_buf_set_option(buf, "buftype", "nofile")
vim.api.nvim_buf_set_option(buf, "buftype", buftype)
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
vim.api.nvim_buf_set_option(buf, "swapfile", false)
vim.api.nvim_buf_set_option(buf, "buflisted", false)
Expand Down
3 changes: 2 additions & 1 deletion lua/wf/fuzzy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local au = require("wf.util").au

local function input_obj_gen(opts, cursor)
local _row_offset = row_offset() + opts.style.input_win_row_offset
local buf, win = gen_obj(_row_offset, opts, cursor)
local buf, win = gen_obj(_row_offset, opts, cursor, "prompt")

au(_g, "BufEnter", function()
local _, _ = pcall(function()
Expand All @@ -15,6 +15,7 @@ local function input_obj_gen(opts, cursor)
end)
end, { buffer = buf })

vim.fn.prompt_setprompt(buf, opts.style.icons.fuzzy_prompt)
local wcnf = vim.api.nvim_win_get_config(win)
vim.api.nvim_win_set_config(
win,
Expand Down
63 changes: 42 additions & 21 deletions lua/wf/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,17 @@ local function fuzzy_setup(which_obj, fuzzy_obj, output_obj, choices_obj, groups
"winhl",
"Normal:WFFocus,FloatBorder:WFFloatBorderFocus"
)
vim.fn.sign_unplace(sign_group_prompt .. "fuzzyfreeze", { buffer = fuzzy_obj.buf })
vim.fn.sign_place(
0,
sign_group_prompt .. "fuzzy",
sign_group_prompt .. "fuzzy",
fuzzy_obj.buf,
{ lnum = 1, priority = 10 }
)

-- TEMP: disable sign
-- vim.fn.sign_unplace(sign_group_prompt .. "fuzzyfreeze", { buffer = fuzzy_obj.buf })
-- vim.fn.sign_place(
-- 0,
-- sign_group_prompt .. "fuzzy",
-- sign_group_prompt .. "fuzzy",
-- fuzzy_obj.buf,
-- { lnum = 1, priority = 10 }
-- )

-- vim.schedule(function()
-- vim.api.nvim_win_set_option(fuzzy_obj.win, "foldcolumn", "1")
-- vim.api.nvim_win_set_option(fuzzy_obj.win, "signcolumn", "yes:2")
Expand Down Expand Up @@ -379,18 +382,23 @@ local function which_setup(
"Normal:WFComment,FloatBorder:WFFloatBorder"
)
end, { buffer = which_obj.buf })
au(_g, { "TextChangedI", "TextChanged" }, vim.schedule_wrap(function()
print("TextChangedI")
print(vim.inspect(vim.api.nvim_get_mode()))
print(vim.api.nvim_buf_get_lines(which_obj.buf,0,-1, true)[1])

local id, text = core(choices_obj, groups_obj, which_obj, fuzzy_obj, output_obj, opts)
if id ~= nil then
obj_handlers.del()
au(
_g,
{ "TextChangedI", "TextChanged" },
vim.schedule_wrap(function()
print("TextChangedI")
print(vim.inspect(vim.api.nvim_get_mode()))
print(vim.api.nvim_buf_get_lines(which_obj.buf, 0, -1, true)[1])

local id, text = core(choices_obj, groups_obj, which_obj, fuzzy_obj, output_obj, opts)
if id ~= nil then
obj_handlers.del()
-- callback(id, text)
async(callback)(id, text)
end
end), { buffer = which_obj.buf })
end
end),
{ buffer = which_obj.buf }
)
au(_g, "WinEnter", winenter, { buffer = which_obj.buf })
-- bmap(which_obj.buf, { "n", "i" }, "<CR>", function()
-- local fuzzy_line = vim.api.nvim_buf_get_lines(fuzzy_obj.buf, 0, -1, true)[1]
Expand Down Expand Up @@ -576,13 +584,26 @@ local function setup_objs(choices_obj, callback, opts_)
-- end))()
vim.schedule(function()
vim.cmd("startinsert!")
-- vim.fn.feedkeys("A", "n")
-- vim.fn.feedkeys("A", "n")
end)

async(_callback)(caller_obj, fuzzy_obj, which_obj, output_obj, choices_obj, groups_obj, callback, opts)
-- _callback(caller_obj, fuzzy_obj, which_obj, output_obj, choices_obj, groups_obj, callback, opts)
-- async(_callback)(
-- caller_obj,
-- fuzzy_obj,
-- which_obj,
-- output_obj,
-- choices_obj,
-- groups_obj,
-- callback,
-- opts
-- )
_callback(caller_obj, fuzzy_obj, which_obj, output_obj, choices_obj, groups_obj, callback, opts)
end

---@param items items
---@param opts the options for wf
---@param on_choice a callback that will be carried
---@usage `require("wf").select(items, opts, on_choice)`
local function select(items, opts, on_choice)
vim.validate({
items = { items, "table", false },
Expand Down
8 changes: 6 additions & 2 deletions lua/wf/output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ end

local function output_obj_gen(opts)
local style = opts.style
local buf, win =
gen_obj(row_offset_() + style.input_win_row_offset + style.input_win_row_offset, opts, false)
local buf, win = gen_obj(
row_offset_() + style.input_win_row_offset + style.input_win_row_offset,
opts,
false,
"nofile"
)
vim.api.nvim_buf_set_option(buf, "filetype", plug_name .. "output")
local wcnf = vim.api.nvim_win_get_config(win)
vim.api.nvim_win_set_config(
Expand Down
12 changes: 6 additions & 6 deletions lua/wf/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function M.async(callback)
local args = { ... }
local handle
handle = vim.loop.new_async(vim.schedule_wrap(function()
-- handle = vim.loop.new_async(function()
-- handle = vim.loop.new_async(function()
if #args > 0 then
callback(unpack(args))
else
Expand Down Expand Up @@ -210,7 +210,7 @@ function M.feedkeys(lhs, count, current, noremap)
-- else
-- vim.api.nvim_feedkeys(M.rt(lhs), noremap and "n" or "m", false)
-- end
vim.api.nvim_feedkeys(M.rt(lhs), noremap and "n" or "m", false)
vim.api.nvim_feedkeys(M.rt(lhs), noremap and "n" or "m", false)
end
local mode = current.mode
if
Expand All @@ -237,10 +237,10 @@ function M.feedkeys(lhs, count, current, noremap)
-- -- vim.api.nvim_feedkeys(M.rt(lhs), noremap and "n" or "m", false)
-- _feedkeys()
-- elseif current_mode == "n" then
if mode == "n" then
-- vim.api.nvim_feedkeys(M.rt(lhs), noremap and "n" or "m", false)
_feedkeys()
end
if mode == "n" then
-- vim.api.nvim_feedkeys(M.rt(lhs), noremap and "n" or "m", false)
_feedkeys()
end
-- else
-- print("current mode: ", current_mode, "\n", "mode: ", mode)
-- print("which-key: mode is not n or i")
Expand Down
14 changes: 13 additions & 1 deletion lua/wf/which.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
local gen_obj = require("wf.common").gen_obj
local row_offset = require("wf.static").row_offset
local static = require("wf.static")
local _g = static._g
local au = require("wf.util").au

local function input_obj_gen(opts, cursor)
local buf, win = gen_obj(row_offset(), opts, cursor)
local buf, win = gen_obj(row_offset(), opts, cursor, "prompt")

au(_g, "BufEnter", function()
local _, _ = pcall(function()
-- turn off the completion
require("cmp").setup.buffer({ enabled = false })
end)
end, { buffer = buf })

vim.fn.prompt_setprompt(buf, opts.style.icons.which_prompt)
local wcnf = vim.api.nvim_win_get_config(win)
vim.api.nvim_win_set_config(
win,
Expand Down

0 comments on commit 9b52e6b

Please sign in to comment.