File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -244,7 +244,7 @@ if the tree was previously open.
244
244
245
245
*nvim-tree.sort_by*
246
246
Changes how files within the same directory are sorted.
247
- Can be one of 'name' , 'case_sensitive' or 'modification_time '.
247
+ Can be one of 'name' , 'case_sensitive', 'modification_time' or 'extension ' .
248
248
Type: `string ` , Default: `" name" `
249
249
250
250
*nvim-tree.hijack_unnamed_buffer_when_opening*
Original file line number Diff line number Diff line change @@ -124,12 +124,38 @@ function M.node_comparator_modification_time(a, b)
124
124
return last_modified_b <= last_modified_a
125
125
end
126
126
127
+ function M .node_comparator_extension (a , b )
128
+ if not (a and b ) then
129
+ return true
130
+ end
131
+
132
+ if a .nodes and not b .nodes then
133
+ return true
134
+ elseif not a .nodes and b .nodes then
135
+ return false
136
+ end
137
+
138
+ if not (a .extension and b .extension ) then
139
+ return true
140
+ end
141
+
142
+ if a .extension and not b .extension then
143
+ return true
144
+ elseif not a .extension and b .extension then
145
+ return false
146
+ end
147
+
148
+ return a .extension :lower () <= b .extension :lower ()
149
+ end
150
+
127
151
function M .setup (opts )
128
152
M .sort_by = opts .sort_by
129
153
if M .sort_by == " modification_time" then
130
154
M .node_comparator = M .node_comparator_modification_time
131
155
elseif M .sort_by == " case_sensitive" then
132
156
M .node_comparator = M .node_comparator_name_case_sensisive
157
+ elseif M .sort_by == " extension" then
158
+ M .node_comparator = M .node_comparator_extension
133
159
else
134
160
M .node_comparator = M .node_comparator_name_ignorecase
135
161
end
You can’t perform that action at this time.
0 commit comments