feat!: Add sortignorecase/sortignoredia options to decouple sorting from searching
* add sortignorecase option for sorting * format code * remove unnecessary position updates * decouple sorting and searching sensitivity options * Decouple sorting and searching case/diacritics sensitivity
This commit is contained in:
5 files changed
+83
-19
No files matched your search
@@ -316,6 +316,8 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase bool (default true)
|
||||
smartdia bool (default false)
|
||||
sortby string (default 'natural')
|
||||
sortignorecase bool (default true)
|
||||
sortignoredia bool (default true)
|
||||
statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
|
||||
tabstop int (default 8)
|
||||
tagfmt string (default "\033[31m")
|
||||
@@ -981,11 +983,11 @@ This option does not have any effect on Windows.
|
||||
|
||||
## ignorecase (bool) (default true)
|
||||
|
||||
Ignore case in sorting and search patterns.
|
||||
Ignore case in search patterns. See also `sortignorecase`.
|
||||
|
||||
## ignoredia (bool) (default true)
|
||||
|
||||
Ignore diacritics in sorting and search patterns.
|
||||
Ignore diacritics in search patterns. See also `sortignoredia`.
|
||||
|
||||
## incfilter (bool) (default false)
|
||||
|
||||
@@ -1197,7 +1199,7 @@ Determines whether file sizes are displayed using binary units (`1K` is 1024 byt
|
||||
|
||||
## smartcase (bool) (default true)
|
||||
|
||||
Override `ignorecase` option when the pattern contains an uppercase character.
|
||||
Override `ignorecase` option for searching when the pattern contains an uppercase character.
|
||||
This option has no effect when `ignorecase` is disabled.
|
||||
|
||||
## smartdia (bool) (default false)
|
||||
@@ -1221,6 +1223,14 @@ The following sort types are supported:
|
||||
ctime time of last status (inode) change
|
||||
custom property defined via `addcustominfo` (empty by default)
|
||||
|
||||
## sortignorecase (bool) (default true)
|
||||
|
||||
Ignore case when sorting. See also `ignorecase`.
|
||||
|
||||
## sortignoredia (bool) (default true)
|
||||
|
||||
Ignore diacritics when sorting. See also `ignoredia`.
|
||||
|
||||
## statfmt (string) (default `\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l`)
|
||||
|
||||
Format string of the file info shown in the bottom left corner.
|
||||
@@ -1494,7 +1504,7 @@ Command `set` is used to set an option which can be a boolean, integer, or strin
|
||||
set sortby "time" # string value with double quotes (backslash escapes)
|
||||
|
||||
Command `setlocal` is used to set a local option for a directory which can be a boolean or string.
|
||||
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse` and `sortby`.
|
||||
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse`, `sortby`, `sortignorecase` and `sortignoredia`.
|
||||
|
||||
setlocal /foo/bar hidden # boolean enable
|
||||
setlocal /foo/bar hidden true # boolean enable
|
||||
|
||||
@@ -328,6 +328,8 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase bool (default true)
|
||||
smartdia bool (default false)
|
||||
sortby string (default 'natural')
|
||||
sortignorecase bool (default true)
|
||||
sortignoredia bool (default true)
|
||||
statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
|
||||
tabstop int (default 8)
|
||||
tagfmt string (default "\033[31m")
|
||||
@@ -1059,11 +1061,11 @@ option does not have any effect on Windows.
|
||||
|
||||
ignorecase (bool) (default true)
|
||||
|
||||
Ignore case in sorting and search patterns.
|
||||
Ignore case in search patterns. See also sortignorecase.
|
||||
|
||||
ignoredia (bool) (default true)
|
||||
|
||||
Ignore diacritics in sorting and search patterns.
|
||||
Ignore diacritics in search patterns. See also sortignoredia.
|
||||
|
||||
incfilter (bool) (default false)
|
||||
|
||||
@@ -1304,8 +1306,9 @@ Determines whether file sizes are displayed using binary units (1K is
|
||||
|
||||
smartcase (bool) (default true)
|
||||
|
||||
Override ignorecase option when the pattern contains an uppercase
|
||||
character. This option has no effect when ignorecase is disabled.
|
||||
Override ignorecase option for searching when the pattern contains an
|
||||
uppercase character. This option has no effect when ignorecase is
|
||||
disabled.
|
||||
|
||||
smartdia (bool) (default false)
|
||||
|
||||
@@ -1328,6 +1331,14 @@ The following sort types are supported:
|
||||
ctime time of last status (inode) change
|
||||
custom property defined via `addcustominfo` (empty by default)
|
||||
|
||||
sortignorecase (bool) (default true)
|
||||
|
||||
Ignore case when sorting. See also ignorecase.
|
||||
|
||||
sortignoredia (bool) (default true)
|
||||
|
||||
Ignore diacritics when sorting. See also ignoredia.
|
||||
|
||||
statfmt (string) (default \033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l)
|
||||
|
||||
Format string of the file info shown in the bottom left corner. This
|
||||
@@ -1643,7 +1654,8 @@ string:
|
||||
|
||||
Command setlocal is used to set a local option for a directory which can
|
||||
be a boolean or string. Currently supported local options are dircounts,
|
||||
dirfirst, dironly, hidden, info, reverse and sortby.
|
||||
dirfirst, dironly, hidden, info, reverse, sortby, sortignorecase and
|
||||
sortignoredia.
|
||||
|
||||
setlocal /foo/bar hidden # boolean enable
|
||||
setlocal /foo/bar hidden true # boolean enable
|
||||
|
||||
@@ -173,6 +173,16 @@ func (e *setExpr) eval(app *app, _ []string) {
|
||||
app.nav.position()
|
||||
app.ui.loadFile(app, true)
|
||||
}
|
||||
case "sortignorecase", "nosortignorecase", "sortignorecase!":
|
||||
err = applyBoolOpt(&gOpts.sortignorecase, e)
|
||||
if err == nil {
|
||||
app.nav.sort()
|
||||
}
|
||||
case "sortignoredia", "nosortignoredia", "sortignoredia!":
|
||||
err = applyBoolOpt(&gOpts.sortignoredia, e)
|
||||
if err == nil {
|
||||
app.nav.sort()
|
||||
}
|
||||
case "watch", "nowatch", "watch!":
|
||||
err = applyBoolOpt(&gOpts.watch, e)
|
||||
if err == nil {
|
||||
@@ -534,6 +544,16 @@ func (e *setLocalExpr) eval(app *app, _ []string) {
|
||||
if err == nil {
|
||||
app.nav.sort()
|
||||
}
|
||||
case "sortignorecase", "nosortignorecase", "sortignorecase!":
|
||||
err = applyLocalBoolOpt(gLocalOpts.sortignorecase, gOpts.sortignorecase, e)
|
||||
if err == nil {
|
||||
app.nav.sort()
|
||||
}
|
||||
case "sortignoredia", "nosortignoredia", "sortignoredia!":
|
||||
err = applyLocalBoolOpt(gLocalOpts.sortignoredia, gOpts.sortignoredia, e)
|
||||
if err == nil {
|
||||
app.nav.sort()
|
||||
}
|
||||
case "info":
|
||||
if e.val == "" {
|
||||
gLocalOpts.info[e.path] = nil
|
||||
|
||||
@@ -179,8 +179,8 @@ type dir struct {
|
||||
visualWrap int // wrap direction in Visual mode (0: none, +: bottom->top, -: top->bottom)
|
||||
hiddenfiles []string // hiddenfiles value from last sort
|
||||
filter []string // last filter for this directory
|
||||
ignorecase bool // ignorecase value from last sort
|
||||
ignoredia bool // ignoredia value from last sort
|
||||
sortignorecase bool // sortignorecase value from last sort
|
||||
sortignoredia bool // sortignoredia value from last sort
|
||||
noPerm bool // whether lf has no permission to open the directory
|
||||
}
|
||||
|
||||
@@ -208,8 +208,8 @@ func (dir *dir) sort() {
|
||||
dir.hidden = getHidden(dir.path)
|
||||
dir.reverse = getReverse(dir.path)
|
||||
dir.hiddenfiles = gOpts.hiddenfiles
|
||||
dir.ignorecase = gOpts.ignorecase
|
||||
dir.ignoredia = gOpts.ignoredia
|
||||
dir.sortignorecase = getSortIgnoreCase(dir.path)
|
||||
dir.sortignoredia = getSortIgnoreDia(dir.path)
|
||||
|
||||
dir.files = dir.allFiles
|
||||
|
||||
@@ -256,10 +256,10 @@ func (dir *dir) sort() {
|
||||
}
|
||||
|
||||
normalize := func(s string) string {
|
||||
if dir.ignorecase {
|
||||
if dir.sortignorecase {
|
||||
s = strings.ToLower(s)
|
||||
}
|
||||
if dir.ignoredia {
|
||||
if dir.sortignoredia {
|
||||
s = removeDiacritics(s)
|
||||
}
|
||||
return s
|
||||
@@ -502,8 +502,8 @@ func (nav *nav) getDir(path string) *dir {
|
||||
reverse: getReverse(path),
|
||||
visualAnchor: -1,
|
||||
hiddenfiles: gOpts.hiddenfiles,
|
||||
ignorecase: gOpts.ignorecase,
|
||||
ignoredia: gOpts.ignoredia,
|
||||
sortignorecase: getSortIgnoreCase(path),
|
||||
sortignoredia: getSortIgnoreDia(path),
|
||||
}
|
||||
nav.dirCache[path] = d
|
||||
return d
|
||||
@@ -546,8 +546,8 @@ func (nav *nav) checkDir(dir *dir) {
|
||||
dir.hidden != getHidden(dir.path) ||
|
||||
dir.reverse != getReverse(dir.path) ||
|
||||
!slices.Equal(dir.hiddenfiles, gOpts.hiddenfiles) ||
|
||||
dir.ignorecase != gOpts.ignorecase ||
|
||||
dir.ignoredia != gOpts.ignoredia:
|
||||
dir.sortignorecase != getSortIgnoreCase(dir.path) ||
|
||||
dir.sortignoredia != getSortIgnoreDia(dir.path):
|
||||
dir.loading = true
|
||||
sd := *dir
|
||||
go func() {
|
||||
|
||||
@@ -144,6 +144,8 @@ var gOpts struct {
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
sortby sortMethod
|
||||
sortignorecase bool
|
||||
sortignoredia bool
|
||||
statfmt string
|
||||
tabstop int
|
||||
tagfmt string
|
||||
@@ -172,6 +174,8 @@ var gLocalOpts struct {
|
||||
info map[string][]string
|
||||
reverse map[string]bool
|
||||
sortby map[string]sortMethod
|
||||
sortignorecase map[string]bool
|
||||
sortignoredia map[string]bool
|
||||
}
|
||||
|
||||
func getDirCounts(path string) bool {
|
||||
@@ -223,6 +227,20 @@ func getSortBy(path string) sortMethod {
|
||||
return gOpts.sortby
|
||||
}
|
||||
|
||||
func getSortIgnoreCase(path string) bool {
|
||||
if val, ok := gLocalOpts.sortignorecase[path]; ok {
|
||||
return val
|
||||
}
|
||||
return gOpts.sortignorecase
|
||||
}
|
||||
|
||||
func getSortIgnoreDia(path string) bool {
|
||||
if val, ok := gLocalOpts.sortignoredia[path]; ok {
|
||||
return val
|
||||
}
|
||||
return gOpts.sortignoredia
|
||||
}
|
||||
|
||||
func init() {
|
||||
gOpts.anchorfind = true
|
||||
gOpts.autoquit = true
|
||||
@@ -287,6 +305,8 @@ func init() {
|
||||
gOpts.smartcase = true
|
||||
gOpts.smartdia = false
|
||||
gOpts.sortby = naturalSort
|
||||
gOpts.sortignorecase = true
|
||||
gOpts.sortignoredia = true
|
||||
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
|
||||
gOpts.tabstop = 8
|
||||
gOpts.tagfmt = "\033[31m"
|
||||
@@ -438,6 +458,8 @@ func init() {
|
||||
gLocalOpts.info = make(map[string][]string)
|
||||
gLocalOpts.reverse = make(map[string]bool)
|
||||
gLocalOpts.sortby = make(map[string]sortMethod)
|
||||
gLocalOpts.sortignorecase = make(map[string]bool)
|
||||
gLocalOpts.sortignoredia = make(map[string]bool)
|
||||
|
||||
setDefaults()
|
||||
}
|
||||
Reference in new issue
Block a user