-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add remember last cursor position indicators & jump functionality (#52)
* feat: Add last cursor position * fix * feat: Add last cursor position config option * feat: Add command to jump to last position * fix: Update last position on mode change * feat: Add support for enter and leave for last position * feat: Export get_last_positions for other plugins * feat: Add support for multiple buffers * refactor: Outsource last_positions into its own module * refactor: Improve formatting * refactor: Improve formatting * docs: Add last position info to README.md * fix: Get correct buffer * chore: Apply stylua
- Loading branch information
Showing
8 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
local last_positions = {} | ||
|
||
---Format a buffer for saving it | ||
---@param buffer number | ||
---@return string | ||
local function format_buf(buffer) | ||
return tostring(buffer) | ||
end | ||
|
||
---Set the last position of the cursor for a buffer | ||
---@param buffer number | ||
---@param mode string | ||
---@param pos number[] | ||
local function set_position(buffer, mode, pos) | ||
if last_positions[format_buf(buffer)] == nil then | ||
return | ||
end | ||
|
||
last_positions[format_buf(buffer)][mode] = pos | ||
end | ||
|
||
---Get the last positions for a buffer. | ||
---Returns an empty table if the buffer is not found. | ||
---@param buffer number | ||
---@return LastPositionsInfo | ||
local function get_positions(buffer) | ||
return last_positions[format_buf(buffer)] or {} | ||
end | ||
|
||
---Register a buffer to be tracked | ||
---We explicitly register buffers to avoid tracking buffers that shouldn't save | ||
---last positions (such as floating windows for example). | ||
---@param buffer any | ||
local function register_buffer(buffer) | ||
last_positions[format_buf(buffer)] = {} | ||
end | ||
|
||
local function unregister_buffer(buffer) | ||
last_positions[format_buf(buffer)] = nil | ||
end | ||
|
||
return { | ||
last_positions = last_positions, | ||
set_position = set_position, | ||
get_positions = get_positions, | ||
register_buffer = register_buffer, | ||
unregister_buffer = unregister_buffer, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters