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>
This commit is contained in:
@@ -191,7 +191,6 @@ Subsequent calls to setup will replace the previous configuration.
|
||||
number = false,
|
||||
relativenumber = false,
|
||||
signcolumn = "yes",
|
||||
-- @deprecated
|
||||
mappings = {
|
||||
custom_only = false,
|
||||
list = {
|
||||
@@ -426,9 +425,25 @@ if the tree was previously open.
|
||||
|
||||
*nvim-tree.sort_by*
|
||||
Changes how files within the same directory are sorted.
|
||||
Can be one of 'name', 'case_sensitive', 'modification_time' or 'extension'.
|
||||
Type: `string`, Default: `"name"`
|
||||
Can be one of `name`, `case_sensitive`, `modification_time`, `extension` or a
|
||||
function.
|
||||
Type: `string` | `function(nodes)`, Default: `"name"`
|
||||
|
||||
Function is passed a table of nodes to be sorted, each node containing:
|
||||
- `absolute_path`: `string`
|
||||
- `executable`: `boolean`
|
||||
- `extension`: `string`
|
||||
- `link_to`: `string`
|
||||
- `name`: `string`
|
||||
- `type`: `"directory"` | `"file"` | `"link"`
|
||||
|
||||
Example: sort by name length: >
|
||||
local sort_by = function(nodes)
|
||||
table.sort(nodes, function(a, b)
|
||||
return #a.name < #b.name
|
||||
end)
|
||||
end
|
||||
<
|
||||
*nvim-tree.hijack_unnamed_buffer_when_opening*
|
||||
Opens in place of the unnamed buffer if it's empty.
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
Reference in New Issue
Block a user