apply 'ignorecase' and 'ignoredia' to sorting

Related #320
This commit is contained in:
Gokcehan 2020-11-06 15:48:28 +03:00
parent 24489924b7
commit c2f2d54cee
4 changed files with 48 additions and 21 deletions

4
doc.go
View File

@ -552,11 +552,11 @@ This option does not have any effect on windows.
ignorecase bool (default on) ignorecase bool (default on)
Ignore case in search patterns. Ignore case in sorting and search patterns.
ignoredia bool (default off) ignoredia bool (default off)
Ignore diacritics in search patterns. Ignore diacritics in sorting and search patterns.
incsearch bool (default off) incsearch bool (default off)

View File

@ -428,13 +428,13 @@ Autocomplete the current word.
cmd-menu-complete cmd-menu-complete
Autocomplete the current word, then you can press the binded key/s Autocomplete the current word, then you can press the binded key/s again to
again to cycle completition options. cycle completition options.
cmd-menu-complete-back cmd-menu-complete-back
Autocomplete the current word, then you can press the binded key/s Autocomplete the current word, then you can press the binded key/s again to
again to cycle completition options backwards. cycle completition options backwards.
cmd-enter (default '<c-j>' and '<enter>') cmd-enter (default '<c-j>' and '<enter>')
@ -582,11 +582,11 @@ have any effect on windows.
ignorecase bool (default on) ignorecase bool (default on)
Ignore case in search patterns. Ignore case in sorting and search patterns.
ignoredia bool (default off) ignoredia bool (default off)
Ignore diacritics in search patterns. Ignore diacritics in sorting and search patterns.
incsearch bool (default off) incsearch bool (default off)

18
lf.1
View File

@ -83,6 +83,8 @@ The following command line commands are provided by lf:
.EX .EX
cmd-escape (default '<esc>') cmd-escape (default '<esc>')
cmd-complete (default '<tab>') cmd-complete (default '<tab>')
cmd-menu-complete
cmd-menu-complete-back
cmd-enter (default '<c-j>' and '<enter>') cmd-enter (default '<c-j>' and '<enter>')
cmd-interrupt (default '<c-c>') cmd-interrupt (default '<c-c>')
cmd-history-next (default '<c-n>') cmd-history-next (default '<c-n>')
@ -491,6 +493,18 @@ Quit command line mode and return to normal mode.
.PP .PP
Autocomplete the current word. Autocomplete the current word.
.PP .PP
.EX
cmd-menu-complete
.EE
.PP
Autocomplete the current word, then you can press the binded key/s again to cycle completition options.
.PP
.EX
cmd-menu-complete-back
.EE
.PP
Autocomplete the current word, then you can press the binded key/s again to cycle completition options backwards.
.PP
.EX .EX
cmd-enter (default '<c-j>' and '<enter>') cmd-enter (default '<c-j>' and '<enter>')
.EE .EE
@ -656,13 +670,13 @@ Sets 'IFS' variable in shell commands. It works by adding the assignment to the
ignorecase bool (default on) ignorecase bool (default on)
.EE .EE
.PP .PP
Ignore case in search patterns. Ignore case in sorting and search patterns.
.PP .PP
.EX .EX
ignoredia bool (default off) ignoredia bool (default off)
.EE .EE
.PP .PP
Ignore diacritics in search patterns. Ignore diacritics in sorting and search patterns.
.PP .PP
.EX .EX
incsearch bool (default off) incsearch bool (default off)

35
nav.go
View File

@ -134,6 +134,18 @@ func newDir(path string) *dir {
} }
} }
func normalize(s1, s2 string) (string, string) {
if gOpts.ignorecase {
s1 = strings.ToLower(s1)
s2 = strings.ToLower(s2)
}
if gOpts.ignoredia {
s1 = removeDiacritics(s1)
s2 = removeDiacritics(s2)
}
return s1, s2
}
func (dir *dir) sort() { func (dir *dir) sort() {
dir.sortType = gOpts.sortType dir.sortType = gOpts.sortType
dir.hiddenfiles = gOpts.hiddenfiles dir.hiddenfiles = gOpts.hiddenfiles
@ -143,11 +155,13 @@ func (dir *dir) sort() {
switch gOpts.sortType.method { switch gOpts.sortType.method {
case naturalSort: case naturalSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
return naturalLess(strings.ToLower(dir.files[i].Name()), strings.ToLower(dir.files[j].Name())) s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name())
return naturalLess(s1, s2)
}) })
case nameSort: case nameSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
return strings.ToLower(dir.files[i].Name()) < strings.ToLower(dir.files[j].Name()) s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name())
return s1 < s2
}) })
case sizeSort: case sizeSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
@ -167,23 +181,22 @@ func (dir *dir) sort() {
}) })
case extSort: case extSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
leftExt := strings.ToLower(dir.files[i].ext) ext1, ext2 := normalize(dir.files[i].ext, dir.files[j].ext)
rightExt := strings.ToLower(dir.files[j].ext)
// if the extension could not be determined (directories, files without) // if the extension could not be determined (directories, files without)
// use a zero byte so that these files can be ranked higher // use a zero byte so that these files can be ranked higher
if leftExt == "" { if ext1 == "" {
leftExt = "\x00" ext1 = "\x00"
} }
if rightExt == "" { if ext2 == "" {
rightExt = "\x00" ext2 = "\x00"
} }
name1, name2 := normalize(dir.files[i].Name(), dir.files[j].Name())
// in order to also have natural sorting with the filenames // in order to also have natural sorting with the filenames
// combine the name with the ext but have the ext at the front // combine the name with the ext but have the ext at the front
left := leftExt + strings.ToLower(dir.files[i].Name()) return (ext1 + name1) < (ext2 + name2)
right := rightExt + strings.ToLower(dir.files[j].Name())
return left < right
}) })
} }