Added builtins/__modules.lua
Script defines all tools available by presser.nvim, which are lazy-loaded and executed when called by the user. Function presser@find_replace has undergone major refactorisation: - Keymaps have been updated to respect new codebase structure. - A new OOP implementation is being experimented for constructing windows, giving future flexibility. Consult presser/steamers.lua. - Function now calls the class@streamers and invokes the streamers@new() method. This constructs the windows/buffers which was originally done via call to presser@new(). - This function is NOT directly accessed, but via proxy table@builtins which lazy-loads function. Any new tools which are created for presser are to be defined in this file and lazy-loaded. Module may be renamed in future for theming consistency.
This commit is contained in:
parent
028b34bdda
commit
b14fadee45
83
presser/builtins/__modules.lua
Normal file
83
presser/builtins/__modules.lua
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
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
|
||||||
Loading…
Reference in New Issue
Block a user