From fe42beb3e4ac00f07884880b7a6251c59fd04230 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Tue, 8 Sep 2020 07:46:21 +0200 Subject: dirlist: fix empty row if dir is added There is a window where a new dir entry isn't yet in the dirlist.dir. dirlist.ensureScroll however expected to always find a valid index. Add a check so that we don't try to scroll to a -1 index. --- widgets/dirlist.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'widgets') diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 3ed79cc..aca1491 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -270,6 +270,12 @@ func (dirlist *DirectoryList) drawScrollbar(ctx *ui.Context, percentVisible floa func (dirlist *DirectoryList) ensureScroll(h int) { selectingIdx := findString(dirlist.dirs, dirlist.selecting) + if selectingIdx < 0 { + // dir not found, meaning we are currently adding / removing a dir. + // we can simply ignore this until we get redrawn with the new + // dirlist.dir content + return + } maxScroll := len(dirlist.dirs) - h if maxScroll < 0 { -- cgit 1.4.1-2-gfad0