Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F132239
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lua/ivy/controller.lua b/lua/ivy/controller.lua
index f6dba23..28cf2fd 100644
--- a/lua/ivy/controller.lua
+++ b/lua/ivy/controller.lua
@@ -1,67 +1,71 @@
local window = require "ivy.window"
local prompt = require "ivy.prompt"
local controller = {}
controller.items = nil
controller.callback = nil
controller.run = function(name, items, callback)
controller.callback = callback
controller.items = items
window.initialize()
window.set_items { "-- Loading ---" }
vim.api.nvim_buf_set_name(window.get_buffer(), name)
controller.input ""
end
controller.input = function(char)
prompt.input(char)
- vim.schedule(function()
- window.set_items(controller.items(prompt.text()))
- end)
+ controller.update(prompt.text())
end
controller.search = function(value)
prompt.set(value)
+ controller.update(prompt.text())
+end
+
+controller.update = function(text)
vim.schedule(function()
- window.set_items(controller.items(prompt.text()))
+ window.set_items(controller.items(text))
+ vim.cmd("syntax clear IvyMatch")
+ vim.cmd("syntax match IvyMatch '[(" .. text .. ")]'")
end)
end
controller.complete = function()
controller.checkpoint()
controller.destroy()
end
controller.checkpoint = function()
vim.api.nvim_set_current_win(window.origin)
controller.callback(window.get_current_selection())
vim.api.nvim_set_current_win(window.window)
end
controller.next = function()
window.index = window.index + 1
window.update()
end
controller.previous = function()
window.index = window.index - 1
window.update()
end
controller.origin = function()
return vim.api.nvim_win_get_buf(window.origin)
end
controller.destroy = function()
controller.items = nil
controller.callback = nil
window.destroy()
prompt.destroy()
end
return controller
diff --git a/plugin/ivy.lua b/plugin/ivy.lua
index 2744c71..bf1262b 100644
--- a/plugin/ivy.lua
+++ b/plugin/ivy.lua
@@ -1,69 +1,71 @@
local controller = require "ivy.controller"
local utils = require "ivy.utils"
local libivy = require "ivy.libivy"
-- Put the controller in to the vim global so we can access it in mappings
-- better without requires. You can call controller commands like `vim.ivy.xxx`.
vim.ivy = controller
vim.api.nvim_create_user_command("IvyAg", function()
vim.ivy.run("AG", utils.command_finder "ag", utils.vimgrep_action())
end, { bang = true, desc = "Run ag to search for content in files" })
vim.api.nvim_create_user_command("IvyFd", function()
vim.ivy.run("Files", function(term)
return libivy.ivy_files(term, vim.fn.getcwd())
end, utils.file_action())
end, { bang = true, desc = "Find files in the project" })
vim.api.nvim_create_user_command("IvyBuffers", function()
vim.ivy.run("Buffers", function(input)
local list = {}
local buffers = vim.api.nvim_list_bufs()
for index = 1, #buffers do
local buffer = buffers[index]
-- Get the relative path from the current working directory. We need to
-- substring +2 to remove the `/` from the start of the path to give us a
-- true relative path
local buffer_name = vim.api.nvim_buf_get_name(buffer):sub(#vim.fn.getcwd() + 2, -1)
if vim.api.nvim_buf_is_loaded(buffer) and #buffer_name > 0 then
local score = libivy.ivy_match(input, buffer_name)
if score > -200 or #input == 0 then
table.insert(list, { score, buffer_name })
end
end
end
table.sort(list, function(a, b)
return a[1] < b[1]
end)
return list
end, utils.file_action())
end, { bang = true, desc = "List all of the current open buffers" })
vim.api.nvim_create_user_command("IvyLines", function()
vim.ivy.run("Lines", function(input)
local list = {}
local lines = vim.api.nvim_buf_get_lines(vim.ivy.origin(), 0, -1, false)
for index = 1, #lines do
local line = lines[index]
local score = libivy.ivy_match(input, line)
if score > -200 then
local prefix = string.rep(" ", 4 - #tostring(index)) .. index .. ": "
table.insert(list, { score, prefix .. line })
end
end
table.sort(list, function(a, b)
return a[1] < b[1]
end)
return list
end, utils.line_action())
end, { bang = true, desc = "List all of the current open buffers" })
vim.api.nvim_set_keymap("n", "<leader>b", "<cmd>IvyBuffers<CR>", { nowait = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>p", "<cmd>IvyFd<CR>", { nowait = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>/", "<cmd>IvyAg<CR>", { nowait = true, silent = true })
+
+vim.cmd "highlight IvyMatch cterm=bold"
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, May 8, 4:58 PM (1 w, 11 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8950
Default Alt Text
(4 KB)
Attached To
Mode
R1 ivy.nvim
Attached
Detach File
Event Timeline
Log In to Comment