Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ If it hasn't been uncompressed, there will be a `+` to the left of it. If it has

If you want to disable dotfiles from being shown, run `set filemanager-showdotfiles false` in Micro, then close & open the tree.\
If you want to disable VCS-ignored (aka `.gitignore`) files from being shown, run `set filemanager-showignored false` in Micro, then close & open the tree.\
If you don't want to go to a parent directory from any selected file via left arrow key (filemanager.compress_at_cursor keybinding), run `set filemanager-compressparent false`
If you don't want to go to a parent directory from any selected file via left arrow key (filemanager.compress_at_cursor keybinding), run `set filemanager-compressparent false`.\
If you don't want to list child folders before child files in a folder, run `set filemanager-foldersfirst false`.

**NOTE:** If you change files without using the plugin, it can't know what you did. The only fix is to close and open the tree.

Expand Down
58 changes: 31 additions & 27 deletions filemanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ if GetOption("filemanager-compressparent") == nil then
AddOption("filemanager-compressparent", true)
end

-- Let the user choose to list sub-folders first when listing the contents of a folder
if GetOption("filemanager-foldersfirst") == nil then
AddOption("filemanager-foldersfirst", true)
end

-- Clear out all stuff in Micro's messenger
local function clear_messenger()
messenger:Reset()
Expand Down Expand Up @@ -152,6 +157,7 @@ local function get_scanlist(dir, ownership, indent_n)

-- The list of files to be returned (and eventually put in the view)
local results = {}
local files = {}

local function get_results_object(file_name)
local abs_path = JoinPaths(dir, file_name)
Expand All @@ -163,9 +169,10 @@ local function get_scanlist(dir, ownership, indent_n)
-- Save so we don't have to rerun GetOption a bunch
local show_dotfiles = GetOption("filemanager-showdotfiles")
local show_ignored = GetOption("filemanager-showignored")
local folders_first = GetOption("filemanager-foldersfirst")

-- The list of VCS-ignored files (if any)
-- Only bother gettig ignored files if we're not showing ignored
-- Only bother getting ignored files if we're not showing ignored
local ignored_files = (not show_ignored and get_ignored_files(dir) or {})
-- True/false if the file is an ignored file
local function is_ignored_file(filename)
Expand All @@ -180,39 +187,36 @@ local function get_scanlist(dir, ownership, indent_n)
-- Hold the current scan's filename in most of the loops below
local filename

-- Splitting the loops for speed, so we don't run an unnecessary if every pass
if not show_dotfiles and not show_ignored then
-- Don't show dotfiles or ignored
for i = 1, #dir_scan do
filename = dir_scan[i]:Name()
-- Check if it's a hidden file
if not is_dotfile(filename) and not is_ignored_file(filename) then
-- Since we skip indicies of dotfiles, don't use i here or we add nil values
results[#results + 1] = get_results_object(filename)
end
for i = 1, #dir_scan do
local showfile = true
filename = dir_scan[i]:Name()
-- If we should not show dotfiles, and this is a dotfile, don't show
if not show_dotfiles and is_dotfile(filename) then
showfile = false
end
elseif show_dotfiles and not show_ignored then
-- Show dotfiles but not ignored
for i = 1, #dir_scan do
filename = dir_scan[i]:Name()
if not is_ignored_file(filename) then
results[#results + 1] = get_results_object(filename)
end
-- If we should not show ignored files, and this is an ignored file, don't show
if not show_ignored and is_ignored_file(filename) then
showfile = false
end
elseif not show_dotfiles and show_ignored then
-- Show ignored but not dotfiles
for i = 1, #dir_scan do
filename = dir_scan[i]:Name()
if not is_dotfile(filename) then
if showfile then
-- This file is good to show, proceed
if folders_first and not is_dir(JoinPaths(dir,filename)) then
-- If folders_first and this is a file, add it to (temporary) files
files[#files + 1] = get_results_object(filename)
else
-- Otherwise, add to results
results[#results + 1] = get_results_object(filename)
end
end
else
-- Show dotfiles and ignored (aka everything)
for i = 1, #dir_scan do
results[i] = get_results_object(dir_scan[i]:Name())
end
if #files > 0 then
-- Append any files to results, now that all folders have been added
-- files will be > 0 only if folders_first and there are files
for i = 0, #files do
Copy link
Collaborator

@sum01 sum01 Aug 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indicies start on 1 in Lua (unless you specifically create a zero index). This is (probably) what's causing the issues with try_open_at_y, as when it goes to access it, it gets a nil value.

Change that 0 to a 1 & I should be able to merge this.

results[#results + 1] = files[i]
end
end

-- Return the list of scanned files
return results
end
Expand Down