Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
refactor(portion): rename to get_line and make it a private method
Browse files Browse the repository at this point in the history
  • Loading branch information
utilyre committed Mar 8, 2023
1 parent 52402a1 commit 127c2ce
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lua/sentiment/ui/Portion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,18 @@ function Portion:get_bottom() return self.viewport[2] end

---Get the line under the cursor.
---
---@param cursor? tuple<integer, integer>
---@private
---@param cursor tuple<integer, integer>
---@return string
function Portion:get_current_line(cursor)
cursor = cursor or self.cursor
function Portion:get_line(cursor)
return self.lines[cursor[1] - self.viewport[1] + 1]
end

---Get the character under the cursor.
---
---@param cursor? tuple<integer, integer>
---@return string
function Portion:get_current_char(cursor)
cursor = cursor or self.cursor
return self:get_current_line(cursor):sub(cursor[2], cursor[2])
function Portion:get_current_char()
return self:get_line(self.cursor):sub(self.cursor[2], self.cursor[2])
end

---Iterate over all characters of the Portion, ignoring newline characters.
Expand All @@ -85,7 +83,7 @@ function Portion:iter(reversed)
local cursor = vim.deepcopy(self.cursor)

return function()
local line = self:get_current_line(cursor)
local line = self:get_line(cursor)
cursor[2] = cursor[2] + coefficient
if reversed and (cursor[2] < 1) or (cursor[2] > #line) then
cursor[1] = cursor[1] + coefficient
Expand All @@ -97,7 +95,7 @@ function Portion:iter(reversed)
return nil
end

line = self:get_current_line(cursor)
line = self:get_line(cursor)
cursor[2] = reversed and #line or 1
end

Expand Down

0 comments on commit 127c2ce

Please sign in to comment.