Skip to content

Commit ffde36a

Browse files
committed
feat: add focused window minwidth and minheight options
Adds options to set minimum width and height for the focused window. This allows users to customize the size of the focused window.
1 parent d76338e commit ffde36a

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ require("focus").setup({
117117
height = 0, -- Force height for the focused window
118118
minwidth = 0, -- Force minimum width for the unfocused window
119119
minheight = 0, -- Force minimum height for the unfocused window
120+
focusedwindow_minwidth = 0, --Force minimum width for the focused window
121+
focusedwindow_minheight = 0, --Force minimum height for the focused window
120122
height_quickfix = 10, -- Set the height of quickfix panel
121123
},
122124
split = {
@@ -187,6 +189,13 @@ require("focus").setup({ autoresize = { width = 120 } })
187189
require("focus").setup({ autoresize = { minwidth = 80} })
188190
```
189191

192+
**Set Focus Minimum Width for Focused Window**
193+
```lua
194+
-- Force minimum width for the focused window
195+
-- Default: Calculated based on golden ratio
196+
require("focus").setup({ autoresize = { focusedwindow_minwidth = 80} })
197+
```
198+
190199
**Set Focus Height**
191200
```lua
192201
-- Force height for the focused window
@@ -201,6 +210,13 @@ require("focus").setup({ autoresize = { height = 40 } })
201210
require("focus").setup({ autoresize = { minheight = 10} })
202211
```
203212

213+
**Set Focus Minimum Height for Focused Window**
214+
```lua
215+
-- Force minimum height for the focused window
216+
-- Default: Calculated based on golden ratio
217+
require("focus").setup({ autoresize = { focusedwindow_minheight = 80} })
218+
```
219+
204220
**Set Focus Quickfix Height**
205221
```lua
206222
-- Sets the height of quickfix panel, in case you pass the height to

doc/focus.txt

+24-6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ default settings:
8080
height = 0, -- Force height for the focused window
8181
minwidth = 0, -- Force minimum width for the unfocused window
8282
minheight = 0, -- Force minimum height for the unfocused window
83+
focusedwindow_minwidth = 0, -- Force minimum width for the focused window
84+
focusedwindow_minheight = 0, -- Force minimum height for the focused window
8385
height_quickfix = 10, -- Set the height of quickfix panel
8486
},
8587
split = {
@@ -91,7 +93,7 @@ default settings:
9193
relativenumber = false, -- Display relative line numbers in the focussed window only
9294
hybridnumber = false, -- Display hybrid line numbers in the focussed window only
9395
absolutenumber_unfocussed = false, -- Preserve absolute numbers in the unfocussed windows
94-
96+
9597
cursorline = true, -- Display a cursorline in the focussed window only
9698
cursorcolumn = false, -- Display cursorcolumn in the focussed window only
9799
colorcolumn = {
@@ -154,6 +156,14 @@ SETUP OPTIONS ~
154156
require("focus").setup({ autoresize = { minwidth = 80} })
155157
<
156158

159+
**Set Focus Minimum Width for Focused Window**
160+
161+
>lua
162+
-- Force minimum width for the focused window
163+
-- Default: Calculated based on golden ratio
164+
require("focus").setup({ autoresize = { focusedwindow_minwidth = 80} })
165+
<
166+
157167
**Set Focus Height**
158168

159169
>lua
@@ -170,6 +180,14 @@ SETUP OPTIONS ~
170180
require("focus").setup({ autoresize = { minheight = 10} })
171181
<
172182

183+
**Set Focus Minimum Height for Focused Window**
184+
185+
>lua
186+
-- Force minimum height for the focused window
187+
-- Default: Calculated based on golden ratio
188+
require("focus").setup({ autoresize = { focusedwindow_minheight = 80} })
189+
<
190+
173191
**Set Focus Quickfix Height**
174192

175193
>lua
@@ -287,7 +305,7 @@ buffer**
287305
-- Enable auto highlighting for focussed/unfocussed windows
288306
-- Default: false
289307
require("focus").setup({ ui = { winhighlight = true } })
290-
308+
291309
-- By default, the highlight groups are setup as such:
292310
-- hi default link FocusedWindow VertSplit
293311
-- hi default link UnfocusedWindow Normal
@@ -312,10 +330,10 @@ Here is an example:
312330
>lua
313331
local ignore_filetypes = { 'neo-tree' }
314332
local ignore_buftypes = { 'nofile', 'prompt', 'popup' }
315-
333+
316334
local augroup =
317335
vim.api.nvim_create_augroup('FocusDisable', { clear = true })
318-
336+
319337
vim.api.nvim_create_autocmd('WinEnter', {
320338
group = augroup,
321339
callback = function(_)
@@ -328,7 +346,7 @@ Here is an example:
328346
end,
329347
desc = 'Disable focus autoresize for BufType',
330348
})
331-
349+
332350
vim.api.nvim_create_autocmd('FileType', {
333351
group = augroup,
334352
callback = function(_)
@@ -473,7 +491,7 @@ LEVERAGE HJKL TO MOVE OR CREATE YOUR SPLITS DIRECTIONALLY ~
473491
require('focus').split_command(direction)
474492
end, { desc = string.format('Create or move to split (%s)', direction) })
475493
end
476-
494+
477495
-- Use `<Leader>h` to split the screen to the left, same as command FocusSplitLeft etc
478496
focusmap('h')
479497
focusmap('j')

extras/repro.lua

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ require('focus').setup({
3737
height = 0, -- Force height for the focused window
3838
minwidth = 0, -- Force minimum width for the unfocused window
3939
minheight = 0, -- Force minimum height for the unfocused window
40+
focusedwindow_minwidth = 0, -- Force minimum width for the focused window
41+
focusedwindow_minheight = 0, -- Force minimum height for the focused window
4042
height_quickfix = 10, -- Set the height of quickfix panel
4143
},
4244
split = {

lua/focus/init.lua

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Focus.config = {
2727
height = 0, -- Force height for the focused window
2828
minwidth = 0, -- Force minimum width for the unfocused window
2929
minheight = 0, -- Force minimum height for the unfocused window
30+
focusedwindow_minwidth = 0, -- Force minimum width for the focused window
31+
focusedwindow_minheight = 0, -- Force minimum height for the focused window
3032
height_quickfix = 10, -- Set the height of quickfix panel
3133
},
3234
split = {
@@ -196,6 +198,14 @@ H.setup_config = function(config)
196198
['autoresize.height'] = { config.autoresize.height, 'number' },
197199
['autoresize.minwidth'] = { config.autoresize.minwidth, 'number' },
198200
['autoresize.minheight'] = { config.autoresize.minheight, 'number' },
201+
['autoresize.focusedwindow_minwidth'] = {
202+
config.autoresize.focusedwindow_minwidth,
203+
'number',
204+
},
205+
['autoresize.focusedwindow_minheight'] = {
206+
config.autoresize.focusedwindow_minheight,
207+
'number',
208+
},
199209
['autoresize.height_quickfix'] = {
200210
config.autoresize.height_quickfix,
201211
'number',

lua/focus/modules/resizer.lua

+10
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ function M.autoresize(config)
5454
width = config.autoresize.width
5555
else
5656
width = golden_ratio_width()
57+
if config.autoresize.focusedwindow_minwidth > 0 then
58+
if width < config.autoresize.focusedwindow_minwidth then
59+
width = config.autoresize.focusedwindow_minwidth
60+
end
61+
end
5762
if config.autoresize.minwidth > 0 then
5863
width = math.max(width, config.autoresize.minwidth)
5964
elseif width < golden_ratio_minwidth() then
@@ -66,6 +71,11 @@ function M.autoresize(config)
6671
height = config.autoresize.height
6772
else
6873
height = golden_ratio_height()
74+
if config.autoresize.focusedwindow_minheight > 0 then
75+
if height < config.autoresize.focusedwindow_minheight then
76+
height = config.autoresize.focusedwindow_minheight
77+
end
78+
end
6979
if config.autoresize.minheight > 0 then
7080
height = math.max(height, config.autoresize.minheight)
7181
elseif height < golden_ratio_minheight() then

0 commit comments

Comments
 (0)