diff options
author | Robin Jarry <robin@jarry.cc> | 2023-04-10 16:56:04 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-04-15 17:26:37 +0200 |
commit | 66995d17eea2a45a4e8d88a7739db18c13b91bf7 (patch) | |
tree | ef57d125b88f547645599c368dea71dd59f35a83 /widgets | |
parent | 8e66f3c364354959abaea2517bf5c18d2fee92ab (diff) | |
download | aerc-66995d17eea2a45a4e8d88a7739db18c13b91bf7.tar.gz |
dialog: avoid panic when window is too small
Avoid negative offsets and limit height to the parent context height.
Fixes: https://todo.sr.ht/~rjarry/aerc/142
Reported-by: Akspecs <akspecs@gmail.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/selector.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/widgets/selector.go b/widgets/selector.go index deefdfbf..fb8c8094 100644 --- a/widgets/selector.go +++ b/widgets/selector.go @@ -206,8 +206,20 @@ func (gp *SelectorDialog) ContextHeight() (func(int) int, func(int) int) { totalHeight := 2 // title + empty line totalHeight += strings.Count(gp.prompt, "\n") + 1 totalHeight += 2 // empty line + selector - start := func(h int) int { return h/2 - totalHeight/2 } - height := func(h int) int { return totalHeight } + start := func(h int) int { + s := h/2 - totalHeight/2 + if s < 0 { + s = 0 + } + return s + } + height := func(h int) int { + if totalHeight > h { + return h + } else { + return totalHeight + } + } return start, height } |