Skip to content

Commit

Permalink
fix(fzf_opts): add 'top'/'bottom' options (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 authored Feb 26, 2024
1 parent 5b4a003 commit a4272cd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
- uses: ytanikin/PRConventionalCommits@1.1.0
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert","break"]'
luacheck:
name: Lua Check
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -31,16 +31,17 @@ jobs:
args: --config-path .stylua.toml ./lua ./spec ./bin
- name: Install commons.nvim
if: ${{ github.ref != 'refs/heads/main' }}
shell: bash
run: |
git clone --depth=1 https://github.com/linrongbin16/commons.nvim.git ~/.commons.nvim
rm -rf ./lua/fzfx/commons
cp -rf ~/.commons.nvim/lua/commons ./lua/fzfx/
cp ~/.commons.nvim/version.txt ./lua/fzfx/commons/version.txt
find ./lua/fzfx/commons -type f -name '*.lua' -exec sed -i 's/"commons./"fzfx.commons./g' {} \;
- uses: lunarmodules/luacheck@v1
with:
args: lua --config .luacheckrc
- uses: cargo-bins/cargo-binstall@main
- name: Selene
run: |
cargo binstall --no-confirm selene
selene --config selene.toml ./lua
- uses: stevearc/nvim-typecheck-action@v1
with:
path: lua
Expand All @@ -55,7 +56,7 @@ jobs:
unit_test:
name: Unit Test
needs:
- luacheck
- lint
strategy:
matrix:
nvim_version: [stable, nightly, v0.7.0]
Expand All @@ -74,7 +75,6 @@ jobs:
- name: Run Tests
run: |
sudo apt-get -y -qq install bat
luarocks install luacheck
luarocks install vusted
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
Expand All @@ -83,7 +83,7 @@ jobs:
code_coverage:
name: Code Coverage
needs:
- luacheck
- lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
11 changes: 8 additions & 3 deletions lua/fzfx/detail/fzf_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ local FZF_DEFAULT_BORDER_OPTS = constants.IS_WINDOWS and "single" or "rounded"
-- see: https://man.archlinux.org/man/fzf.1.en#preview-window=
-- --preview-window=[POSITION][,SIZE[%]][,border-BORDER_OPT][,[no]wrap][,[no]follow][,[no]cycle][,[no]hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]
--
--- @alias fzfx.FzfPreviewWindowOptsNoAlternative {position:"up"|"down"|"left"|"right",size:integer,size_is_percent:boolean,border:string,wrap:boolean,follow:boolean,cycle:boolean,hidden:boolean,scroll:string?,header_lines:integer?}
--- @alias fzfx.FzfPreviewWindowOptsNoAlternative {position:"top"|"bottom"|"up"|"down"|"left"|"right",size:integer,size_is_percent:boolean,border:string,wrap:boolean,follow:boolean,cycle:boolean,hidden:boolean,scroll:string?,header_lines:integer?}
--
--- @param split_opts string[]
--- @return fzfx.FzfPreviewWindowOptsNoAlternative
Expand All @@ -478,8 +478,13 @@ local function parse_fzf_preview_window_opts_no_alternative(split_opts)
header_lines = nil,
}
for i, o in ipairs(split_opts) do
if o == "up" or o == "down" or o == "left" or o == "right" then
if o == "up" or o == "down" or o == "top" or o == "bottom" or o == "left" or o == "right" then
result.position = o
if o == "top" then
result.position = "up"
elseif o == "bottom" then
result.position = "down"
end
elseif strings.endswith(o, "%") then
result.size = tonumber(string.sub(o, 1, #o - 1))
elseif
Expand Down Expand Up @@ -549,7 +554,7 @@ end

-- see: https://man.archlinux.org/man/fzf.1.en#preview-window=
-- --preview-window=[POSITION][,SIZE[%]][,border-BORDER_OPT][,[no]wrap][,[no]follow][,[no]cycle][,[no]hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]
--- @alias fzfx.FzfPreviewWindowOpts {position:"up"|"down"|"left"|"right",size:integer,size_is_percent:boolean,border:string,wrap:boolean,follow:boolean,cycle:boolean,hidden:boolean,scroll:string?,header_lines:integer?,size_threshold:integer?,alternative_layout:fzfx.FzfPreviewWindowOptsNoAlternative?}
--- @alias fzfx.FzfPreviewWindowOpts {position:"top"|"bottom"|"up"|"down"|"left"|"right",size:integer,size_is_percent:boolean,border:string,wrap:boolean,follow:boolean,cycle:boolean,hidden:boolean,scroll:string?,header_lines:integer?,size_threshold:integer?,alternative_layout:fzfx.FzfPreviewWindowOptsNoAlternative?}
--
--- @param opts fzfx.FzfOpt[]
--- @return fzfx.FzfPreviewWindowOpts
Expand Down
1 change: 1 addition & 0 deletions selene.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ mixed_table = "allow"
unused_variable = "allow"
incorrect_standard_library_use = "allow"
global_usage = "allow"
if_same_then_else = "allow"
6 changes: 3 additions & 3 deletions spec/detail/fzf_helpers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ describe("detail.fzf_helpers", function()
assert_eq(actual5.size_is_percent, true)
assert_eq(actual5.follow, false)
local actual6 = fzf_helpers.parse_fzf_preview_window_opts({
"--preview-window=down,3,border-bold,nowrap,follow",
"--preview-window=top,3,border-bold,nowrap,follow",
})
print(string.format("parse fzf --preview-window-12:%s\n", vim.inspect(actual6)))
assert_eq(actual6.position, "down")
assert_eq(actual6.position, "up")
assert_eq(actual6.size, 3)
assert_eq(actual6.size_is_percent, false)
assert_eq(type(actual6.border), "table")
Expand All @@ -421,7 +421,7 @@ describe("detail.fzf_helpers", function()
assert_eq(actual7.cycle, true)
assert_eq(actual7.hidden, true)
local actual8 = fzf_helpers.parse_fzf_preview_window_opts({
"--preview-window=down,3,border-bold,nowrap,follow,nocycle,nohidden",
"--preview-window=bottom,3,border-bold,nowrap,follow,nocycle,nohidden",
})
print(string.format("parse fzf --preview-window-14:%s\n", vim.inspect(actual8)))
assert_eq(actual8.position, "down")
Expand Down
23 changes: 12 additions & 11 deletions spec/detail/popup/popup_helpers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ describe("detail.popup.popup_helpers", function()
end)
end)
describe("[make_layout]", function()
local function isclose(a, b, tolerance)
tolerance = tolerance or 2.0
return math.abs(a - b) <= tolerance
local function isclose(a, b)
return math.abs(a - b) <= 3.5
end

it("test1 without fzf_preview_window_opts", function()
Expand Down Expand Up @@ -99,7 +98,7 @@ describe("detail.popup.popup_helpers", function()
assert_true(isclose(actual.width, width))
assert_true(isclose(actual.height, height))
assert_true(isclose(2 * (center_row - actual.start_row), height))
assert_true(isclose(2 * (actual.end_row - center_row), height, 3))
assert_true(isclose(2 * (actual.end_row - center_row), height))
assert_true(isclose(2 * (center_col - actual.start_col), width))
assert_true(isclose(2 * (actual.end_col - center_col), width))
end)
Expand Down Expand Up @@ -198,9 +197,9 @@ describe("detail.popup.popup_helpers", function()
assert_true(isclose(actual.width, width))
assert_true(isclose(actual.height, height))
assert_true(isclose(2 * (center_row - actual.start_row), height))
assert_true(isclose(2 * (actual.end_row - center_row), height, 3))
assert_true(isclose(2 * (actual.end_row - center_row), height))
assert_true(isclose(2 * (center_col - actual.start_col), width))
assert_true(isclose(2 * (actual.end_col - center_col), width, 3))
assert_true(isclose(2 * (actual.end_col - center_col), width))

assert_true(isclose(actual.provider.height, height - 15 - 1))
assert_eq(actual.provider.width, width)
Expand Down Expand Up @@ -245,23 +244,25 @@ describe("detail.popup.popup_helpers", function()

assert_true(isclose(actual.width, width))
assert_true(isclose(actual.height, height))
assert_true(isclose(2 * (center_row - actual.start_row), height, 3))
assert_true(isclose(2 * (actual.end_row - center_row), height, 3))
assert_true(isclose(2 * (center_row - actual.start_row), height))
assert_true(isclose(2 * (actual.end_row - center_row), height))
assert_true(isclose(2 * (center_col - actual.start_col), width))
assert_true(isclose(2 * (actual.end_col - center_col), width, 3))
assert_true(isclose(2 * (actual.end_col - center_col), width))

if total_height > 20 then
assert_true(isclose(actual.provider.height, height - 15 - 1))
end
assert_true(isclose(actual.provider.width, width))
assert_true(
isclose(actual.provider.start_row, actual.start_row + actual.previewer.height + 1, 3)
isclose(actual.provider.start_row, actual.start_row + actual.previewer.height + 1)
)
assert_eq(actual.provider.end_row, actual.end_row)
assert_eq(actual.provider.start_col, actual.start_col)
assert_eq(actual.provider.end_col, actual.end_col)

assert_true(isclose(actual.previewer.height, 15 - 1))
if total_height > 20 then
assert_true(isclose(actual.previewer.height, 15 - 1))
end
assert_true(isclose(actual.previewer.width, width))
assert_eq(actual.previewer.start_row, actual.start_row)
assert_eq(actual.previewer.end_row, actual.start_row + actual.previewer.height)
Expand Down

0 comments on commit a4272cd

Please sign in to comment.