8000 mini.nvim/lua/mini/bracketed.lua at main · dimhatz/mini.nvim · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
2016 lines (1704 loc) · 79.6 KB

bracketed.lua

File metadata and controls

2016 lines (1704 loc) · 79.6 KB
--- - Now try one of the following (each one after performing previous steps in
--- separate new buffer):
--- - Press `u`. It goes back to empty buffer. Press `<C-R>` twice and it
--- goes to the latest change (`one two`). No way to get to other states
--- (like `two three` or `one three`) with these two keys.
---
--- - Press `g-`. It goes to an empty buffer. Press `g+` 4 times. It cycles
--- through all available undo states **in order they were created**.
---
--- - Finally, press `[u`. It goes back to `one two` - state which was
--- **previously visited** by the user. Another `[u` restores `one two three`.
--- Use `]U` to go to latest visited undo state.
---
---@param direction __bracketed_direction
---@param opts __bracketed_opts
MiniBracketed.undo = function(direction, opts)
if H.is_disabled() then return end
H.validate_direction(direction, { 'first', 'backward', 'forward', 'last' }, 'undo')
opts = vim.tbl_deep_extend('force', { n_times = vim.v.count1, wrap = true }, H.get_config().undo.options, opts or {})
-- Define iterator that traverses undo states in order they appeared
local buf_id = vim.api.nvim_get_current_buf()
H.undo_sync(buf_id, vim.fn.undotree())
local iterator = {}
local buf_history = H.cache.undo[buf_id]
local n = #buf_history
iterator.next = function(id)
if id == nil or n <= id then return end
return id + 1
end
iterator.prev = function(id)
if id == nil or id <= 1 then return end
return id - 1
end
iterator.state = buf_history.current_id
iterator.start_edge = 0
iterator.end_edge = n + 1
0