Skip to content

Commit

Permalink
feat: make all the things repeatable without needing expr=true
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 16, 2023
1 parent 2f76471 commit ec3a8ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
10 changes: 4 additions & 6 deletions lua/flash/commands.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
local State = require("flash.state")
local Util = require("flash.util")
local Repeat = require("flash.repeat")

---@class Flash.Commands
local M = {}

---@param opts? Flash.Config
---@param opts? Flash.State.Config
function M.jump(opts)
local state = State.new(opts)
local state = Repeat.get_state("jump", opts)

while true do
local c = Util.get_char()
Expand All @@ -32,13 +31,12 @@ function M.jump(opts)
end

-- exit if no results
if #state.results == 0 then
if #state.results == 0 and #pattern > 0 then
break
end
end
state:hide()
return state
end

-- M.jump = Repeat.wrap(M.jump)

return M
31 changes: 13 additions & 18 deletions lua/flash/plugins/charsearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,20 @@ end

function M.setup()
for key in pairs(M.keys) do
vim.keymap.set(
{ "n", "x", "o" },
key,
Repeat.wrap(function(is_repeat)
if is_repeat and M.state then
M.jumping = true
M.state:jump()
vim.schedule(function()
M.jumping = false
end)
return
end
vim.keymap.set({ "n", "x", "o" }, key, function()
if Repeat.is_repeat then
M.jumping = true
M.state:jump({ count = vim.v.count1 })
M.state:show()
vim.schedule(function()
M.jumping = false
end)
else
M.jump(key)
end),
{
silent = true,
expr = true,
}
)
end
end, {
silent = true,
})
end

vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved", "InsertEnter" }, {
Expand Down
9 changes: 2 additions & 7 deletions lua/flash/plugins/treesitter.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local State = require("flash.state")
local Repeat = require("flash.repeat")
local Util = require("flash.util")

local M = {}
Expand Down Expand Up @@ -42,12 +42,7 @@ end

M.state = nil
function M.jump()
if M.state then
M.state:hide()
M.state = nil
end

M.state = State.new({
M.state = Repeat.get_state("treesitter", {
matcher = M.matcher,
labels = "abcdefghijklmnopqrstuvwxyz",
search = { multi_window = false, wrap = true },
Expand Down

0 comments on commit ec3a8ac

Please sign in to comment.