From c82d3d5e3df2fa5922934103b0c4cfd73278d2a1 Mon Sep 17 00:00:00 2001 From: mwishoff Date: Wed, 6 Dec 2023 08:40:47 -0800 Subject: [PATCH 1/4] Added harpoon_wrap option to default config as true. Reference this option in list:prev and list:next. When true allows prev and next to wrap the harpoon list, when false it will not wrap the harpoon list. --- lua/harpoon/config.lua | 1 + lua/harpoon/list.lua | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua index 260f004..a341492 100644 --- a/lua/harpoon/config.lua +++ b/lua/harpoon/config.lua @@ -74,6 +74,7 @@ function M.get_default_config() }, default = { + harpoon_wrap = true, --- select_with_nill allows for a list to call select even if the provided item is nil select_with_nil = false, diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua index 20a44e3..4d01385 100644 --- a/lua/harpoon/list.lua +++ b/lua/harpoon/list.lua @@ -171,8 +171,11 @@ end function HarpoonList:next() self._index = self._index + 1 - if self._index > #self.items then + print(self._index) + if self._index > #self.items and self.config.harpoon_wrap then self._index = 1 + elseif self._index > #self.items and not self.config.harpoon_wrap then + self._index = #self.items end self:select(self._index) @@ -180,8 +183,11 @@ end function HarpoonList:prev() self._index = self._index - 1 - if self._index < 1 then + print(self._index) + if self._index < 1 and self.config.harpoon_wrap then self._index = #self.items + elseif self._index < 1 and not self.config.harpoon_wrap then + self._index = 1 end self:select(self._index) From 9ff11a310ae9e9e92318b286df8de04d6f796f48 Mon Sep 17 00:00:00 2001 From: mwishoff Date: Wed, 6 Dec 2023 08:42:17 -0800 Subject: [PATCH 2/4] Remove debug statements. --- lua/harpoon/list.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua index 4d01385..8a9f211 100644 --- a/lua/harpoon/list.lua +++ b/lua/harpoon/list.lua @@ -171,7 +171,6 @@ end function HarpoonList:next() self._index = self._index + 1 - print(self._index) if self._index > #self.items and self.config.harpoon_wrap then self._index = 1 elseif self._index > #self.items and not self.config.harpoon_wrap then @@ -183,7 +182,6 @@ end function HarpoonList:prev() self._index = self._index - 1 - print(self._index) if self._index < 1 and self.config.harpoon_wrap then self._index = #self.items elseif self._index < 1 and not self.config.harpoon_wrap then From 4bd2c4c792b4583f88ce47a61a1e7658e9545aa3 Mon Sep 17 00:00:00 2001 From: mwishoff Date: Wed, 6 Dec 2023 16:23:40 -0800 Subject: [PATCH 3/4] Fixing linting and formatting checks. --- lua/harpoon/test/logger_spec.lua | 2 +- lua/harpoon/utils.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/harpoon/test/logger_spec.lua b/lua/harpoon/test/logger_spec.lua index 4d95a49..d97054d 100644 --- a/lua/harpoon/test/logger_spec.lua +++ b/lua/harpoon/test/logger_spec.lua @@ -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 diff --git a/lua/harpoon/utils.lua b/lua/harpoon/utils.lua index f99df98..de632c3 100644 --- a/lua/harpoon/utils.lua +++ b/lua/harpoon/utils.lua @@ -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+", " ") @@ -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 From 038bde660c373f7f6bfe79200ec5b8b7bc4d2418 Mon Sep 17 00:00:00 2001 From: mwishoff Date: Sat, 9 Dec 2023 15:14:05 -0800 Subject: [PATCH 4/4] Renamed harpoon_wrap to ui_nav_wrap. --- lua/harpoon/config.lua | 4 +++- lua/harpoon/list.lua | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua index a341492..f101c97 100644 --- a/lua/harpoon/config.lua +++ b/lua/harpoon/config.lua @@ -74,7 +74,9 @@ function M.get_default_config() }, default = { - harpoon_wrap = true, + --- 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, diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua index 8a9f211..13e891c 100644 --- a/lua/harpoon/list.lua +++ b/lua/harpoon/list.lua @@ -171,9 +171,9 @@ end function HarpoonList:next() self._index = self._index + 1 - if self._index > #self.items and self.config.harpoon_wrap 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.harpoon_wrap then + elseif self._index > #self.items and not self.config.ui_nav_wrap then self._index = #self.items end @@ -182,9 +182,9 @@ end function HarpoonList:prev() self._index = self._index - 1 - if self._index < 1 and self.config.harpoon_wrap then + if self._index < 1 and self.config.ui_nav_wrap then self._index = #self.items - elseif self._index < 1 and not self.config.harpoon_wrap then + elseif self._index < 1 and not self.config.ui_nav_wrap then self._index = 1 end