Skip to content

Commit

Permalink
refactor: optimization of internal configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
obaland committed Jul 28, 2023
1 parent 853cc01 commit 2291bfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lua/vfiler/vfiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function VFiler.new(context)
local self = setmetatable({
_buffer = buffer,
_context = context,
_view = View.new(context),
_view = View.new(context.options),
_mappings = nil,
_event = nil,
}, VFiler)
Expand Down Expand Up @@ -314,7 +314,7 @@ function VFiler:update(context)

-- set buffer options
self._buffer:set_option('buflisted', context.options.listed)
self._view:reset(context)
self._view:reset(context.options)
end

--- Is the filer visible?
Expand Down
23 changes: 11 additions & 12 deletions lua/vfiler/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ local View = {}
View.__index = View

--- Create a view object
---@param context table
function View.new(context)
---@param options table
function View.new(options)
local self = setmetatable({
_buffer = nil,
_gitstatus = nil,
_window = nil,
_winconfig = {},
_winoptions = {
Expand All @@ -122,7 +123,7 @@ function View.new(context)
wrap = false,
},
}, View)
self:reset(context)
self:reset(options)
return self
end

Expand Down Expand Up @@ -152,13 +153,12 @@ function View:draw(context)
end

local options = context.options
self._gitstatus = context.gitstatus
self:_flatten_items(
context.root,
sort.get(options.sort),
context.gitstatus,
options.show_hidden_files
)

self:redraw()
end

Expand Down Expand Up @@ -369,10 +369,9 @@ function View:redraw_line(lnum)
})
end

--- Reset from another context
---@param context table
function View:reset(context)
local options = context.options
--- Reset from another options
---@param options table
function View:reset(options)
self._columns = create_columns(options.columns)
if not self._columns then
return nil
Expand Down Expand Up @@ -530,9 +529,9 @@ function View:_create_column_props(width)
return props
end

function View:_flatten_items(item, sort_compare, gitstatus, show_hidden_files)
function View:_flatten_items(item, sort_compare, show_hidden_files)
-- Override gitstatus of items
item.gitstatus = gitstatus[item.path]
item.gitstatus = self._gitstatus[item.path]

local children = item.children
if not children then
Expand All @@ -551,7 +550,7 @@ function View:_flatten_items(item, sort_compare, gitstatus, show_hidden_files)
prev_sibling = #self._items

-- recursive flattening
self:_flatten_items(child, sort_compare, gitstatus, show_hidden_files)
self:_flatten_items(child, sort_compare, show_hidden_files)

if i ~= #children then
index.next_sibling = prev_sibling + (#self._items - prev_sibling) + 1
Expand Down

0 comments on commit 2291bfa

Please sign in to comment.