Skip to content

Commit

Permalink
adding more space at the top
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Badragan committed May 8, 2024
1 parent e90f622 commit 0295990
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lua/grug-far/farBuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ local function setupRenderer(win, buf, context)

if context.state.isFirstRender then
context.state.isFirstRender = false
vim.api.nvim_win_set_cursor(win, { 2, 0 })
vim.api.nvim_win_set_cursor(win, { 3, 0 })
end
end

Expand Down
38 changes: 33 additions & 5 deletions lua/grug-far/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,39 @@ local renderInput = require('grug-far/render/input')
local renderResults = require('grug-far/render/results')
local utils = require('grug-far/utils')

local function ensureTopEmptyLines(buf, count)
local lines = vim.api.nvim_buf_get_lines(buf, 0, count, false)
for _ = #lines + 1, count do
table.insert(lines, nil)
end

local foundNonEmpty = false
local emptyLines = {}
for i = 1, #lines do
local line = lines[i]
foundNonEmpty = foundNonEmpty or not (line and #line == 0)
if foundNonEmpty then table.insert(emptyLines, "") end
end

if #emptyLines > 0 then
vim.api.nvim_buf_set_lines(buf, 0, 0, false, emptyLines)
end
end

local TOP_EMPTY_LINES = 2

local function render(params, context)
local buf = params.buf
local inputs = context.state.inputs

local lineNr = 0
ensureTopEmptyLines(buf, TOP_EMPTY_LINES)
renderHelp({ buf = buf }, context)

lineNr = lineNr + TOP_EMPTY_LINES
inputs.search = renderInput({
buf = buf,
lineNr = 1,
lineNr = lineNr,
extmarkName = "search",
icon = 'searchInput',
label = "Search:",
Expand All @@ -21,36 +45,40 @@ local function render(params, context)
vim.api.nvim_buf_set_name(buf,
'Grug FAR' .. utils.strEllideAfter(inputs.search, context.options.maxSearchCharsInTitles, ': '))

lineNr = lineNr + 1
inputs.replacement = renderInput({
buf = buf,
lineNr = 2,
lineNr = lineNr,
extmarkName = "replace",
icon = 'replaceInput',
label = "Replace:",
placeholder = "ex: bar ${1}_foo $$MY_ENV_VAR ",
}, context)

lineNr = lineNr + 1
inputs.filesGlob = vim.trim(renderInput({
buf = buf,
lineNr = 3,
lineNr = lineNr,
extmarkName = "files_glob",
icon = 'filesFilterInput',
label = "Files Filter:",
placeholder = "ex: *.lua *.{css,js} **/docs/*.md",
}, context))

lineNr = lineNr + 1
inputs.flags = vim.trim(renderInput({
buf = buf,
lineNr = 4,
lineNr = lineNr,
extmarkName = "flags",
icon = 'flagsInput',
label = "Flags:",
placeholder = "ex: --hidden (-.) --ignore-case (-i) --multiline (-U)",
}, context))

lineNr = lineNr + 2
renderResults({
buf = buf,
minLineNr = 6,
minLineNr = lineNr,
inputs = inputs
}, context)
end
Expand Down
7 changes: 2 additions & 5 deletions lua/grug-far/render/help.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
local function renderHelp(params, context)
local buf = params.buf
local helpLine = unpack(vim.api.nvim_buf_get_lines(buf, 0, 1, false))
if #helpLine ~= 0 then
vim.api.nvim_buf_set_lines(buf, 0, 0, false, { "" })
end

local helpExtmarkPos = context.extmarkIds.help and
vim.api.nvim_buf_get_extmark_by_id(buf, context.namespace, context.extmarkIds.help, {}) or {}
if helpExtmarkPos[1] ~= 0 then
local keymaps = context.options.keymaps
context.extmarkIds.help = vim.api.nvim_buf_set_extmark(buf, context.namespace, 0, 0, {
id = context.extmarkIds.help,
end_row = 0,
end_col = 0,
virt_text = {
{ "Apply Replace: <c-enter> | To Quickfix List: <c-q> | Close: <c-x> | Help: g?", 'GrugFarHelpHeader' }
{ 'Replace: ' .. keymaps.replace .. ' | ' .. ' Open in Quickfix List: ' .. keymaps.qflist .. ' | ' .. ' Close: ' .. keymaps.close, 'GrugFarHelpHeader' }
},
virt_text_pos = 'overlay'
})
Expand Down

0 comments on commit 0295990

Please sign in to comment.