nvim-tree.lua/lua/nvim-tree
KuuWang 3676e0b124
feat(sorters): allow user sort_by
* feat: Mixin Sorter (#1565) Self Solved

adding `mixin` sort options for `rust` like package systems

```

package.rs
package/
  __inside__

lib.rs
lib/
  _inside_

a.rs
b.rs
module.rs

```

* feat: sort_by, after_sort options for more convinient using

```
*nvim-tree.sort_by*
Changes how files within the same directory are sorted.
Can be one of 'name', 'case_sensitive', 'modification_time' or 'extension',
'function'.
>
  sort_by = function(a, b)
    if not (a and b) then
      return true
    end
    if a.nodes and not b.nodes then
      return true
    elseif not a.nodes and b.nodes then
      return false
    end

    return a.name:lower() <= b.name:lower()
  end

  end
  Type: `string | function(a, b)`, Default: `"name"`

*nvim-tree.after_sort*
Related to nvim-tree.sort_by, this function runs without mergesort.
Can be defined by your own after-sort works.
  Type: `function(table)`, Default: `disable`

>
  after_sort = function(t)
    local i = 1

    while i <= #t do
      if t[i] and t[i].nodes then
        local j = i + 1
        while j <= #t do
          if t[j] and not t[j].nodes and t[i].name:lower() == t[j].name:lower():match "(.+)%..+$" then
            local change_target = t[j]
            table.remove(t, j)
            table.insert(t, i, change_target)
            break
          end
          j = j + 1
        end
      end
      i = i + 1
    end
  end

```

* remove: after_sort ( misunderstood feature )

sort_by parameter can be function.

``` lua
  sort_by = function(t)
    local sorters = require "nvim-tree.explorer.sorters"
    local comparator = sorters.retrieve_comparator("name")
    sorters.split_merge(t, 1, #t, comparator) -- run default merge_sort
    local i = 1

    while i <= #t do
      if t[i] and t[i].nodes then
        local j = i + 1
        while j <= #t do
          if t[j] and not t[j].nodes and t[i].name:lower() == t[j].name:lower():match "(.+)%..+$" then
            local change_target = t[j]
            table.remove(t, j)
            table.insert(t, i, change_target)
            break
          end
          j = j + 1
        end
      end
      i = i + 1
    end
  end,

```

* try-fix: change existing merge_sort function, call user's sort_by

hope.. like it...?

* doc: explain function parameter and return, add more complex example

* fix: reorder with user-comparator exceed memory limit

apply merge_sort
check nil & type for senitize

* fix: user_index based sorting ( create index )

for performance, create index once,
using index to re-ordering

* fix: fence problems

* doc & fix: merge_sort problem fix & nil sorting

add complex example

* fix: sort_by detect and use string and nil

* doc: revert sort_by to simple

* fix: sort_by does not return anything

Co-authored-by: Alexander Courtis <alex@courtis.org>
2022-09-18 16:00:49 +10:00
..
actions fix(#1564): reset &bufhidden when opening an existing (maybe previewed) buffer (#1573) 2022-09-05 10:10:58 +10:00
explorer feat(sorters): allow user sort_by 2022-09-18 16:00:49 +10:00
git fix(#1494): git showUntracked value and log (#1504) 2022-08-15 14:30:22 +10:00
iterators feat(bookmarks): add bookmark feature (#1412) 2022-07-11 10:00:12 +02:00
marks fix(#1533): make toggle_mark ignore non-togglable nodes. (#1534) 2022-08-22 14:24:25 +10:00
renderer fix(#1568): show relative path of symlink destination (#1569) 2022-09-04 12:23:56 +10:00
api.lua chore(api): add missing functions 2022-07-25 15:02:55 +02:00
colors.lua feat(bookmarks): add bookmark feature (#1412) 2022-07-11 10:00:12 +02:00
config.lua fix(keypress): use <cmd> instead of : to avoid triggering CmdLineEnter 2022-07-14 09:33:19 +02:00
core.lua chore(watchers): refactor events and make debouncer safe 2022-07-17 08:50:24 +02:00
diagnostics.lua chore(watchers): refactor events and make debouncer safe 2022-07-17 08:50:24 +02:00
events.lua feat(api): add public API module (#1432) 2022-07-25 11:11:48 +02:00
keymap.lua fix: inverted diagnostic navigation keymaps 2022-08-20 14:40:09 +10:00
legacy.lua chore: move nvim-tree.utils.warn -> notify.warn 2022-07-18 13:46:11 +02:00
lib.lua refactor(actions): move actions into semantic modules (#1410) 2022-07-10 09:47:52 +02:00
live-filter.lua fix(view): file filter and info popup above floating view 2022-09-03 14:29:18 +10:00
log.lua feat(notify): switch all print/nvim_*write statements to utils.notify 2022-07-18 14:04:48 +02:00
utils.lua fix(#1555): incorrect exe highlight in Windows filesystem from WSL (#1557) 2022-08-29 10:53:23 +10:00
view.lua feat(view): floating window's optional adaptive size specification (#1559) 2022-08-30 08:50:18 +10:00
watcher.lua chore(watchers): Watcher shares single fs_event from Event, node watchers use unique path prefixed debounce context (#1453) 2022-07-26 10:43:58 +02:00