camspiers / snap

A fast finder system for neovim.
The Unlicense
483 stars 16 forks source link

[FEATURE REQUEST] Resume previous dialog #91

Open tex opened 4 months ago

tex commented 4 months ago

Inlcuding previous initial_filter and position of cursor in search result.

camspiers commented 4 months ago

@tex I provided a comment on this reddit post where I explain how you can achieve this now:

https://www.reddit.com/r/neovim/comments/1d77kok/comment/l6zd5l7/

local snap = require("snap")
local tbl = require("snap.common.tbl")

-- Here we are storing the old version of snap.run
local run = snap.run

-- Here we will store each config that is passed to snap.run
local last_config = nil

-- Here we are overriding snap.run, this isn't the most sane thing to do but it will work
snap.run = function(config)
  last_config = config
  local function on_update(filter)
    if config.on_update then
      config.on_update(filter)
    end
    last_config.initial_filter = filter
  end
  run(tbl.merge(config, { on_update = on_update }))
end

-- Now all usages of snap.run use the above definition and have their config stored,
-- whether they are generated from snap.config, or just plain invocations of snap.run
-- So you can now do all your setups as normal, but you can additionally now register a "last search" style setup

snap.maps({
  {
    "<Leader>i",
    function ()
      if last_config then
        snap.run(last_config)
      end
    end
  }
})
tex commented 4 months ago

Nice, thanks! I saw that reddit article but did not notice he is also using Snap :) Integrating seems like a nice approach. BTW I am working on tags support (gtags/global).

tex commented 3 months ago

Regarding the resuming previous dialog, it is not only about remembering the filter. But also position in the list of results. Ideally it should remember the results and not run producer again when resumed.