diff --git a/presser/builtins/__modules.lua b/presser/builtins/__modules.lua new file mode 100644 index 0000000..b02fa9e --- /dev/null +++ b/presser/builtins/__modules.lua @@ -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 = { + [""] = "lua require'presser.actions'.close()", + [""] = "lua require'presser.actions'.execute()", + }, + i = { + [""] = "lua require'presser.actions'.move_next_buffer()", + [""] = "lua require'presser.actions'.execute()", + } + } + + -- 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