Skip to content

Commit

Permalink
fix: open action when floating.
Browse files Browse the repository at this point in the history
  • Loading branch information
obaland committed Oct 23, 2023
1 parent 2447621 commit a41f75f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 43 deletions.
11 changes: 8 additions & 3 deletions lua/vfiler/actions/utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ local function choose_window(winid)
end

local function open_file(vfiler, context, view, path, layout)
-- TODO:
if view:type() == 'floating' then
vfiler:quit()
end
if layout ~= 'none' then
core.window.open(layout)
end
Expand All @@ -121,9 +125,10 @@ local function open_file(vfiler, context, view, path, layout)

local dest_winid = vim.fn.win_getid()
--if layout ~= 'tab' and dest_winid ~= view:winid() then
if dest_winid ~= view:winid() then
view:redraw()
end
-- TODO:
--if dest_winid ~= view:winid() then
-- view:redraw()
--end
end

local function choose_file(vfiler, context, view, path)
Expand Down
25 changes: 18 additions & 7 deletions tests/vfiler/actions/open/open_by_choose_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ local configs = {
}

describe('open actions', function()
local vfiler = u.vfiler.start(configs)
it(u.vfiler.desc('open by choose', vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_choose)
end)
vfiler:quit(true)
local layouts = {
'none', 'right', 'left', 'top', 'bottom', 'tab', 'floating'
}
for _, layout in ipairs(layouts) do
local configs = {
options = u.vfiler.generate_options(),
}
configs.options.layout = layout
local vfiler = u.vfiler.start(configs)

local message = ('open by choose (%s)'):format(layout)
it(u.vfiler.desc(message, vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_choose)
end)
vfiler:quit(true)
end
end)
29 changes: 18 additions & 11 deletions tests/vfiler/actions/open/open_by_split_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ local core = require('vfiler/libs/core')
local a = require('vfiler/actions/open')
local u = require('tests/utilities')

local configs = {
options = u.vfiler.generate_options(),
}

describe('open actions', function()
local vfiler = u.vfiler.start(configs)
it(u.vfiler.desc('open by split', vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_split)
end)
vfiler:quit(true)
local layouts = {
'none', 'right', 'left', 'top', 'bottom', 'tab', 'floating'
}
for _, layout in ipairs(layouts) do
local configs = {
options = u.vfiler.generate_options(),
}
configs.options.layout = layout
local vfiler = u.vfiler.start(configs)

local message = ('open by split (%s)'):format(layout)
it(u.vfiler.desc(message, vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_split)
end)
vfiler:quit(true)
end
end)
29 changes: 18 additions & 11 deletions tests/vfiler/actions/open/open_by_tabpage_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ local core = require('vfiler/libs/core')
local a = require('vfiler/actions/open')
local u = require('tests/utilities')

local configs = {
options = u.vfiler.generate_options(),
}

describe('open actions', function()
local vfiler = u.vfiler.start(configs)
it(u.vfiler.desc('open by tabpage', vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_tabpage)
end)
vfiler:quit(true)
local layouts = {
'none', 'right', 'left', 'top', 'bottom', 'tab', 'floating'
}
for _, layout in ipairs(layouts) do
local configs = {
options = u.vfiler.generate_options(),
}
configs.options.layout = layout
local vfiler = u.vfiler.start(configs)

local message = ('open by tabpage (%s)'):format(layout)
it(u.vfiler.desc(message, vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_tabpage)
end)
vfiler:quit(true)
end
end)
29 changes: 18 additions & 11 deletions tests/vfiler/actions/open/open_by_vsplit_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ local core = require('vfiler/libs/core')
local a = require('vfiler/actions/open')
local u = require('tests/utilities')

local configs = {
options = u.vfiler.generate_options(),
}

describe('open actions', function()
local vfiler = u.vfiler.start(configs)
it(u.vfiler.desc('open by vsplit', vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_vsplit)
end)
vfiler:quit(true)
local layouts = {
'none', 'right', 'left', 'top', 'bottom', 'tab', 'floating'
}
for _, layout in ipairs(layouts) do
local configs = {
options = u.vfiler.generate_options(),
}
configs.options.layout = layout
local vfiler = u.vfiler.start(configs)

local message = ('open by vsplit (%s)'):format(layout)
it(u.vfiler.desc(message, vfiler), function()
local view = vfiler._view
core.cursor.move(u.int.random(2, view:num_lines()))
vfiler:do_action(a.open_by_vsplit)
end)
vfiler:quit(true)
end
end)

0 comments on commit a41f75f

Please sign in to comment.