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
+119
-55
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)
|
smartcase bool (default true)
|
||||||
smartdia bool (default false)
|
smartdia bool (default false)
|
||||||
sortby string (default 'natural')
|
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")
|
statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
tagfmt string (default "\033[31m")
|
tagfmt string (default "\033[31m")
|
||||||
@@ -981,11 +983,11 @@ This option does not have any effect on Windows.
|
|||||||
|
|
||||||
## ignorecase (bool) (default true)
|
## ignorecase (bool) (default true)
|
||||||
|
|
||||||
Ignore case in sorting and search patterns.
|
Ignore case in search patterns. See also `sortignorecase`.
|
||||||
|
|
||||||
## ignoredia (bool) (default true)
|
## ignoredia (bool) (default true)
|
||||||
|
|
||||||
Ignore diacritics in sorting and search patterns.
|
Ignore diacritics in search patterns. See also `sortignoredia`.
|
||||||
|
|
||||||
## incfilter (bool) (default false)
|
## 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)
|
## 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.
|
This option has no effect when `ignorecase` is disabled.
|
||||||
|
|
||||||
## smartdia (bool) (default false)
|
## smartdia (bool) (default false)
|
||||||
@@ -1221,6 +1223,14 @@ The following sort types are supported:
|
|||||||
ctime time of last status (inode) change
|
ctime time of last status (inode) change
|
||||||
custom property defined via `addcustominfo` (empty by default)
|
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`)
|
## 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.
|
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)
|
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.
|
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 # boolean enable
|
||||||
setlocal /foo/bar hidden true # 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)
|
smartcase bool (default true)
|
||||||
smartdia bool (default false)
|
smartdia bool (default false)
|
||||||
sortby string (default 'natural')
|
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")
|
statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
tagfmt string (default "\033[31m")
|
tagfmt string (default "\033[31m")
|
||||||
@@ -1059,11 +1061,11 @@ option does not have any effect on Windows.
|
|||||||
|
|
||||||
ignorecase (bool) (default true)
|
ignorecase (bool) (default true)
|
||||||
|
|
||||||
Ignore case in sorting and search patterns.
|
Ignore case in search patterns. See also sortignorecase.
|
||||||
|
|
||||||
ignoredia (bool) (default true)
|
ignoredia (bool) (default true)
|
||||||
|
|
||||||
Ignore diacritics in sorting and search patterns.
|
Ignore diacritics in search patterns. See also sortignoredia.
|
||||||
|
|
||||||
incfilter (bool) (default false)
|
incfilter (bool) (default false)
|
||||||
|
|
||||||
@@ -1304,8 +1306,9 @@ Determines whether file sizes are displayed using binary units (1K is
|
|||||||
|
|
||||||
smartcase (bool) (default true)
|
smartcase (bool) (default true)
|
||||||
|
|
||||||
Override ignorecase option when the pattern contains an uppercase
|
Override ignorecase option for searching when the pattern contains an
|
||||||
character. This option has no effect when ignorecase is disabled.
|
uppercase character. This option has no effect when ignorecase is
|
||||||
|
disabled.
|
||||||
|
|
||||||
smartdia (bool) (default false)
|
smartdia (bool) (default false)
|
||||||
|
|
||||||
@@ -1328,6 +1331,14 @@ The following sort types are supported:
|
|||||||
ctime time of last status (inode) change
|
ctime time of last status (inode) change
|
||||||
custom property defined via `addcustominfo` (empty by default)
|
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)
|
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
|
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
|
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,
|
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 # boolean enable
|
||||||
setlocal /foo/bar hidden true # boolean enable
|
setlocal /foo/bar hidden true # boolean enable
|
||||||
|
|||||||
@@ -173,6 +173,16 @@ func (e *setExpr) eval(app *app, _ []string) {
|
|||||||
app.nav.position()
|
app.nav.position()
|
||||||
app.ui.loadFile(app, true)
|
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!":
|
case "watch", "nowatch", "watch!":
|
||||||
err = applyBoolOpt(&gOpts.watch, e)
|
err = applyBoolOpt(&gOpts.watch, e)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -534,6 +544,16 @@ func (e *setLocalExpr) eval(app *app, _ []string) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
app.nav.sort()
|
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":
|
case "info":
|
||||||
if e.val == "" {
|
if e.val == "" {
|
||||||
gLocalOpts.info[e.path] = nil
|
gLocalOpts.info[e.path] = nil
|
||||||
|
|||||||
@@ -162,26 +162,26 @@ func readdir(path string) ([]*file, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type dir struct {
|
type dir struct {
|
||||||
loading bool // whether directory is loading from disk
|
loading bool // whether directory is loading from disk
|
||||||
loadTime time.Time // last load time
|
loadTime time.Time // last load time
|
||||||
ind int // 0-based index of current entry in dir.files
|
ind int // 0-based index of current entry in dir.files
|
||||||
pos int // 0-based cursor row in directory window
|
pos int // 0-based cursor row in directory window
|
||||||
path string // full path of directory
|
path string // full path of directory
|
||||||
files []*file // displayed files in directory including or excluding hidden ones
|
files []*file // displayed files in directory including or excluding hidden ones
|
||||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||||
sortby sortMethod // sortby value from last sort
|
sortby sortMethod // sortby value from last sort
|
||||||
dircounts bool // dircounts value from last sort
|
dircounts bool // dircounts value from last sort
|
||||||
dirfirst bool // dirfirst value from last sort
|
dirfirst bool // dirfirst value from last sort
|
||||||
dironly bool // dironly value from last sort
|
dironly bool // dironly value from last sort
|
||||||
hidden bool // hidden value from last sort
|
hidden bool // hidden value from last sort
|
||||||
reverse bool // reverse value from last sort
|
reverse bool // reverse value from last sort
|
||||||
visualAnchor int // index where Visual mode was initiated
|
visualAnchor int // index where Visual mode was initiated
|
||||||
visualWrap int // wrap direction in Visual mode (0: none, +: bottom->top, -: top->bottom)
|
visualWrap int // wrap direction in Visual mode (0: none, +: bottom->top, -: top->bottom)
|
||||||
hiddenfiles []string // hiddenfiles value from last sort
|
hiddenfiles []string // hiddenfiles value from last sort
|
||||||
filter []string // last filter for this directory
|
filter []string // last filter for this directory
|
||||||
ignorecase bool // ignorecase value from last sort
|
sortignorecase bool // sortignorecase value from last sort
|
||||||
ignoredia bool // ignoredia value from last sort
|
sortignoredia bool // sortignoredia value from last sort
|
||||||
noPerm bool // whether lf has no permission to open the directory
|
noPerm bool // whether lf has no permission to open the directory
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDir(path string) *dir {
|
func newDir(path string) *dir {
|
||||||
@@ -208,8 +208,8 @@ func (dir *dir) sort() {
|
|||||||
dir.hidden = getHidden(dir.path)
|
dir.hidden = getHidden(dir.path)
|
||||||
dir.reverse = getReverse(dir.path)
|
dir.reverse = getReverse(dir.path)
|
||||||
dir.hiddenfiles = gOpts.hiddenfiles
|
dir.hiddenfiles = gOpts.hiddenfiles
|
||||||
dir.ignorecase = gOpts.ignorecase
|
dir.sortignorecase = getSortIgnoreCase(dir.path)
|
||||||
dir.ignoredia = gOpts.ignoredia
|
dir.sortignoredia = getSortIgnoreDia(dir.path)
|
||||||
|
|
||||||
dir.files = dir.allFiles
|
dir.files = dir.allFiles
|
||||||
|
|
||||||
@@ -256,10 +256,10 @@ func (dir *dir) sort() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
normalize := func(s string) string {
|
normalize := func(s string) string {
|
||||||
if dir.ignorecase {
|
if dir.sortignorecase {
|
||||||
s = strings.ToLower(s)
|
s = strings.ToLower(s)
|
||||||
}
|
}
|
||||||
if dir.ignoredia {
|
if dir.sortignoredia {
|
||||||
s = removeDiacritics(s)
|
s = removeDiacritics(s)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
@@ -491,19 +491,19 @@ func (nav *nav) getDir(path string) *dir {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
d := &dir{
|
d := &dir{
|
||||||
loading: true,
|
loading: true,
|
||||||
loadTime: time.Now(),
|
loadTime: time.Now(),
|
||||||
path: path,
|
path: path,
|
||||||
sortby: getSortBy(path),
|
sortby: getSortBy(path),
|
||||||
dircounts: getDirCounts(path),
|
dircounts: getDirCounts(path),
|
||||||
dirfirst: getDirFirst(path),
|
dirfirst: getDirFirst(path),
|
||||||
dironly: getDirOnly(path),
|
dironly: getDirOnly(path),
|
||||||
hidden: getHidden(path),
|
hidden: getHidden(path),
|
||||||
reverse: getReverse(path),
|
reverse: getReverse(path),
|
||||||
visualAnchor: -1,
|
visualAnchor: -1,
|
||||||
hiddenfiles: gOpts.hiddenfiles,
|
hiddenfiles: gOpts.hiddenfiles,
|
||||||
ignorecase: gOpts.ignorecase,
|
sortignorecase: getSortIgnoreCase(path),
|
||||||
ignoredia: gOpts.ignoredia,
|
sortignoredia: getSortIgnoreDia(path),
|
||||||
}
|
}
|
||||||
nav.dirCache[path] = d
|
nav.dirCache[path] = d
|
||||||
return d
|
return d
|
||||||
@@ -546,8 +546,8 @@ func (nav *nav) checkDir(dir *dir) {
|
|||||||
dir.hidden != getHidden(dir.path) ||
|
dir.hidden != getHidden(dir.path) ||
|
||||||
dir.reverse != getReverse(dir.path) ||
|
dir.reverse != getReverse(dir.path) ||
|
||||||
!slices.Equal(dir.hiddenfiles, gOpts.hiddenfiles) ||
|
!slices.Equal(dir.hiddenfiles, gOpts.hiddenfiles) ||
|
||||||
dir.ignorecase != gOpts.ignorecase ||
|
dir.sortignorecase != getSortIgnoreCase(dir.path) ||
|
||||||
dir.ignoredia != gOpts.ignoredia:
|
dir.sortignoredia != getSortIgnoreDia(dir.path):
|
||||||
dir.loading = true
|
dir.loading = true
|
||||||
sd := *dir
|
sd := *dir
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ var gOpts struct {
|
|||||||
smartcase bool
|
smartcase bool
|
||||||
smartdia bool
|
smartdia bool
|
||||||
sortby sortMethod
|
sortby sortMethod
|
||||||
|
sortignorecase bool
|
||||||
|
sortignoredia bool
|
||||||
statfmt string
|
statfmt string
|
||||||
tabstop int
|
tabstop int
|
||||||
tagfmt string
|
tagfmt string
|
||||||
@@ -165,13 +167,15 @@ var gOpts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var gLocalOpts struct {
|
var gLocalOpts struct {
|
||||||
dircounts map[string]bool
|
dircounts map[string]bool
|
||||||
dirfirst map[string]bool
|
dirfirst map[string]bool
|
||||||
dironly map[string]bool
|
dironly map[string]bool
|
||||||
hidden map[string]bool
|
hidden map[string]bool
|
||||||
info map[string][]string
|
info map[string][]string
|
||||||
reverse map[string]bool
|
reverse map[string]bool
|
||||||
sortby map[string]sortMethod
|
sortby map[string]sortMethod
|
||||||
|
sortignorecase map[string]bool
|
||||||
|
sortignoredia map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDirCounts(path string) bool {
|
func getDirCounts(path string) bool {
|
||||||
@@ -223,6 +227,20 @@ func getSortBy(path string) sortMethod {
|
|||||||
return gOpts.sortby
|
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() {
|
func init() {
|
||||||
gOpts.anchorfind = true
|
gOpts.anchorfind = true
|
||||||
gOpts.autoquit = true
|
gOpts.autoquit = true
|
||||||
@@ -287,6 +305,8 @@ func init() {
|
|||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
gOpts.smartdia = false
|
gOpts.smartdia = false
|
||||||
gOpts.sortby = naturalSort
|
gOpts.sortby = naturalSort
|
||||||
|
gOpts.sortignorecase = true
|
||||||
|
gOpts.sortignoredia = true
|
||||||
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
|
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
|
||||||
gOpts.tabstop = 8
|
gOpts.tabstop = 8
|
||||||
gOpts.tagfmt = "\033[31m"
|
gOpts.tagfmt = "\033[31m"
|
||||||
@@ -438,6 +458,8 @@ func init() {
|
|||||||
gLocalOpts.info = make(map[string][]string)
|
gLocalOpts.info = make(map[string][]string)
|
||||||
gLocalOpts.reverse = make(map[string]bool)
|
gLocalOpts.reverse = make(map[string]bool)
|
||||||
gLocalOpts.sortby = make(map[string]sortMethod)
|
gLocalOpts.sortby = make(map[string]sortMethod)
|
||||||
|
gLocalOpts.sortignorecase = make(map[string]bool)
|
||||||
|
gLocalOpts.sortignoredia = make(map[string]bool)
|
||||||
|
|
||||||
setDefaults()
|
setDefaults()
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user