@@ -191,7 +191,6 @@ Subsequent calls to setup will replace the previous configuration.
191
191
number = false,
192
192
relativenumber = false,
193
193
signcolumn = "yes",
194
- -- @deprecated
195
194
mappings = {
196
195
custom_only = false,
197
196
list = {
@@ -466,87 +465,37 @@ For example, to use simple user-defined sort_by function is done like this:
466
465
return user_oder
467
466
end
468
467
469
- Furthermore, You can try more complex example for `rust` sort_by function is done like this:
468
+ Furthermore, You can try more complex example for sort_by function is done like this:
470
469
471
470
>
472
471
sort_by = function(tbl)
473
- local function tbl_slice(t, first, last)
474
- local slice = {}
475
- for i = first, last or #t, 1 do
476
- table.insert(slice, t[i])
477
- end
478
- return slice
479
- end
480
-
481
- local function merge(t, first, mid, last, comparator)
482
- local n1 = mid - first + 1
483
- local n2 = last - mid
484
- local ls = tbl_slice(t, first, mid)
485
- local rs = tbl_slice(t, mid + 1, last)
486
- local i = 1
487
- local j = 1
488
- local k = first
489
- while i <= n1 and j <= n2 do
490
- if comparator(ls[i], rs[j]) then
491
- t[k] = ls[i]
492
- i = i + 1
493
- else
494
- t[k] = rs[j]
495
- j = j + 1
496
- end
497
- k = k + 1
498
- end
499
- while i <= n1 do
500
- t[k] = ls[i]
501
- i = i + 1
502
- k = k + 1
503
- end
504
- while j <= n2 do
505
- t[k] = rs[j]
506
- j = j + 1
507
- k = k + 1
508
- end
509
- end
510
-
511
- local function split_merge(t, first, last, comparator)
512
- if (last - first) < 1 then
513
- return
514
- end
515
-
516
- local mid = math.floor((first + last) / 2)
517
-
518
- split_merge(t, first, mid, comparator)
519
- split_merge(t, mid + 1, last, comparator)
520
- merge(t, first, mid, last, comparator)
521
- end
522
-
523
- local function node_comparator_name_ignorecase_or_not(a, b, ignorecase)
472
+ table.sort(tbl, function(a, b)
524
473
if not (a and b) then
525
474
return true
526
475
end
527
- if a.nodes and not b.nodes then
476
+ if a.type == "directory" and b.type ~= "directory" then
528
477
return true
529
- elseif not a.nodes and b.nodes then
478
+ elseif a.type ~= "directory" and b.type == "directory" then
530
479
return false
531
480
end
532
481
533
- if ignorecase then
534
- return a.name:lower() <= b.name:lower()
535
- else
536
- return a.name <= b.name
482
+ if a.type == "link" and b.type ~= "link" then
483
+ return true
484
+ elseif a.type ~= "link" and b.type == "link" then
485
+ return false
537
486
end
538
- end
539
-
540
487
541
- local comparartor = function(a, b) node_comparator_name_ignorecase_or_not(a, b, true) end
542
- split_merge(tbl, 1, #tbl, comparartor)
488
+ return a.name:lower() <= b.name:lower()
489
+ -- return a.name <= b.name
490
+ end) -- NOTE: organize directory, link, file in name order
543
491
492
+ -- sort by name, is directory?
544
493
local i = 1
545
494
while i <= #tbl do
546
- if tbl[i] and tbl[i].nodes then
495
+ if tbl[i] and tbl[i].type == "directory" then
547
496
local j = i + 1
548
497
while j <= #tbl do
549
- if tbl[j] and not tbl[j].nodes and tbl[i].name:lower() == tbl[j].name:lower():match "(.+)%..+$" then
498
+ if tbl[j] and tbl[j].type ~= "directory" and tbl[i].name:lower() == tbl[j].name:lower():match "(.+)%..+$" then
550
499
local change_target = tbl[j]
551
500
table.remove(tbl, j)
552
501
table.insert(tbl, i, change_target)
@@ -560,12 +509,12 @@ Furthermore, You can try more complex example for `rust` sort_by function is don
560
509
561
510
local user_order = {}
562
511
for j = 1, #tbl do
563
- table.insert(user_order, tbl[j].absolute_path)
512
+ if tbl[j] then
513
+ table.insert(user_order, tbl[j].absolute_path)
514
+ end
564
515
end
565
516
return user_order
566
- end,
567
-
568
-
517
+ end
569
518
570
519
*nvim-tree.hijack_unnamed_buffer_when_opening*
571
520
Opens in place of the unnamed buffer if it's empty.
0 commit comments