Skip to content

Commit

Permalink
Introduce 'adjust_window' option to enable or disable automatic windo…
Browse files Browse the repository at this point in the history
…w adjustment. (#36)
  • Loading branch information
nsoufian committed Oct 28, 2023
1 parent 10d51dd commit bb323ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use {
min_height = 5,
max_width = 120,
max_height = 25,
adjust_window = true,
keymaps = {
close = "q",
next_match = "n",
Expand Down
17 changes: 10 additions & 7 deletions lua/ssr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local config = {
min_height = 5,
max_width = 120,
max_height = 25,
adjust_window = true,
keymaps = {
close = "q",
next_match = "n",
Expand Down Expand Up @@ -137,13 +138,15 @@ function Ui.new()
group = self.augroup,
buffer = self.ui_buf,
callback = function()
local lines = api.nvim_buf_get_lines(self.ui_buf, 0, -1, true)
local width, height = u.get_win_size(lines, config)
if api.nvim_win_get_width(ui_win) ~= width then
api.nvim_win_set_width(ui_win, width)
end
if api.nvim_win_get_height(ui_win) ~= height then
api.nvim_win_set_height(ui_win, height)
if config.adjust_window then
local lines = api.nvim_buf_get_lines(self.ui_buf, 0, -1, true)
local width, height = u.get_win_size(lines, config)
if api.nvim_win_get_width(ui_win) ~= width then
api.nvim_win_set_width(ui_win, width)
end
if api.nvim_win_get_height(ui_win) ~= height then
api.nvim_win_set_height(ui_win, height)
end
end
self:search()
end,
Expand Down

0 comments on commit bb323ba

Please sign in to comment.