folder filter: only assume regex if filter is ~fmt

This commit is contained in:
Drew DeVault 2019-08-20 13:04:21 +09:00
parent 1f5293931a
commit 334ca89bea
2 changed files with 10 additions and 5 deletions

View file

@ -226,7 +226,7 @@ Note that many of these configuration options are written for you, such as
*folders* *folders*
Specifies the comma separated list of folders to display in the sidebar. Specifies the comma separated list of folders to display in the sidebar.
Supports regex patterns. Names prefixed with ~ are interpreted as regular expressions.
Default: all folders Default: all folders

View file

@ -161,12 +161,17 @@ func (dirlist *DirectoryList) Prev() {
} }
func folderMatches(folder string, pattern string) bool { func folderMatches(folder string, pattern string) bool {
if len(pattern) == 0 {
return false
}
if pattern[0] == '~' {
r, err := regexp.Compile(pattern) r, err := regexp.Compile(pattern)
if err != nil { if err != nil {
return false return false
} }
return r.Match([]byte(folder)) return r.Match([]byte(folder))
}
return pattern == folder
} }
// filterDirsByFoldersConfig sets dirlist.dirs to the filtered subset of the // filterDirsByFoldersConfig sets dirlist.dirs to the filtered subset of the