Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to disable/enable wrapping on next/prev when cycling through harpoon lists. #387

Merged
merged 4 commits into from
Dec 10, 2023
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: 3 additions & 0 deletions lua/harpoon/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ function M.get_default_config()
},

default = {
--- ui_nav_wrap allows the ability to enable(true) or disable(false) wrapping on prev and next list calls.
ui_nav_wrap = true,

--- select_with_nill allows for a list to call select even if the provided item is nil
select_with_nil = false,

Expand Down
8 changes: 6 additions & 2 deletions lua/harpoon/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,21 @@ end

function HarpoonList:next()
self._index = self._index + 1
if self._index > #self.items then
if self._index > #self.items and self.config.ui_nav_wrap then
self._index = 1
elseif self._index > #self.items and not self.config.ui_nav_wrap then
self._index = #self.items
end

self:select(self._index)
end

function HarpoonList:prev()
self._index = self._index - 1
if self._index < 1 then
if self._index < 1 and self.config.ui_nav_wrap then
self._index = #self.items
elseif self._index < 1 and not self.config.ui_nav_wrap then
self._index = 1
end

self:select(self._index)
Expand Down
2 changes: 1 addition & 1 deletion lua/harpoon/test/logger_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local utils = require("harpoon.test.utils")
--local utils = require("harpoon.test.utils")
local Logger = require("harpoon.logger")

local eq = assert.are.same
Expand Down
6 changes: 3 additions & 3 deletions lua/harpoon/utils.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}

function M.trim(str)
return str:gsub("^%s+", ""):gsub("%s+$", "")
return str:gsub("^%s+", ""):gsub("%s+$", "")
end
function M.remove_duplicate_whitespace(str)
return str:gsub("%s+", " ")
Expand All @@ -11,8 +11,8 @@ function M.split(str, sep)
if sep == nil then
sep = "%s"
end
local t={}
for s in string.gmatch(str, "([^"..sep.."]+)") do
local t = {}
for s in string.gmatch(str, "([^" .. sep .. "]+)") do
table.insert(t, s)
end
return t
Expand Down
Loading