Created new director lua/ and moved presser/ into the subdirectory. This is to align with other standard developments of Neovim extensions.
84 lines
2.1 KiB
Lua
84 lines
2.1 KiB
Lua
local gcm = require'presser.context_manager'
|
|
local steamers = require'presser.steamers'
|
|
local actions = require'presser.actions'
|
|
|
|
local a = vim.api
|
|
|
|
local modules = {}
|
|
|
|
-- @Description: Find and replace words within the current buffer.
|
|
-- @Params:
|
|
-- @Returns: nil.
|
|
--
|
|
-- @Dev: function is responsible to creating all required buffers to allow full user interaction.
|
|
--
|
|
-- @Future: implementation may allow for greater user customisation similar to what's found with
|
|
-- extensions such as Telescope. For now, it should provide a concrete UI for purpose of design.
|
|
modules.find_replace = function ()
|
|
-- define the context which these windows will belong to in the context manager.
|
|
local ctx = "find_replace"
|
|
gcm.create( ctx )
|
|
|
|
local keymap = {
|
|
n = {
|
|
["<esc>"] = "<cmd>lua require'presser.actions'.close()<CR>",
|
|
["<A-a>"] = "<cmd>lua require'presser.actions'.execute()<CR>",
|
|
},
|
|
i = {
|
|
["<down>"] = "<cmd>lua require'presser.actions'.move_next_buffer()<CR>",
|
|
["<A-a>"] = "<cmd>lua require'presser.actions'.execute()<CR>",
|
|
}
|
|
}
|
|
|
|
-- get the centre of the current buffer
|
|
local c_cols = math.floor( a.nvim_win_get_width(0) / 2 )
|
|
local c_lines = math.floor( a.nvim_win_get_height(0) / 2 )
|
|
|
|
-- create a title buffer for the steamer
|
|
steamers
|
|
.new( ctx, {
|
|
label = "presser_title",
|
|
steamer = {
|
|
placeholder = "Find & Replace",
|
|
allowed = false,
|
|
window = {
|
|
line = c_lines - 3,
|
|
border = false,
|
|
minwidth = 82,
|
|
padding = { 0, 1, 1, 1 }
|
|
}
|
|
}
|
|
} )
|
|
|
|
-- create a new buffer for find pattern
|
|
steamers
|
|
.new ( ctx, {
|
|
label = "find_buf",
|
|
steamer = {
|
|
window = {
|
|
line = c_lines,
|
|
title = "Find",
|
|
},
|
|
keybinds = keymap,
|
|
}
|
|
} )
|
|
|
|
-- create a new buffer for replace pattern
|
|
steamers
|
|
.new( ctx, {
|
|
label = "replace_buf",
|
|
steamer = {
|
|
window = {
|
|
line = c_lines + 3,
|
|
title = "Replace",
|
|
},
|
|
keybinds = keymap,
|
|
}
|
|
} )
|
|
|
|
local result = actions.buf_put_curser_at( "find_buf" )
|
|
a.nvim_feedkeys('A', 'n', false)
|
|
end
|
|
|
|
return modules
|