Skip to content

feat: enhance cycle forward function#601

Merged
dmtrKovalenko merged 8 commits into
dmtrKovalenko:mainfrom
thuan1412:feat/enhance-cycle-forward-function
Jun 16, 2026
Merged

feat: enhance cycle forward function#601
dmtrKovalenko merged 8 commits into
dmtrKovalenko:mainfrom
thuan1412:feat/enhance-cycle-forward-function

Conversation

@thuan1412

@thuan1412 thuan1412 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Will be ready after #438

This PR enhances the behavior of the cycle query forawd by:

  • if current offset is nil (new session), the forward will do nothing.
  • if current offset is nil (from resume function) or the offset is 0, then clear the input.

Before

before.mov

After

Screen.Recording.2026-06-14.at.21.25.08.mov

Add ability to resume the last closed picker with full state (query,
results, cursor, mode) by adapting for the refactored module structure.

In the coordinator (picker_ui.lua):
- save_state_and_close() deep-copies picker state before closing
- restore_from_state() recreates UI from saved snapshot
- M.close() overrides the wired close to save state then call close_windows
- M.resume(), M.resume_find_files(), M.resume_live_grep() public API
- Per-mode saved state (find_files vs live_grep)

In layout_manager.lua:
- Extracted close_windows() as the low-level cleanup
- close() now delegates to close_windows()

In main.lua:
- find_files and live_grep support opts.resume
- M.resume() public API for :FFFResume command

plugin/fff.lua:
- :FFFResume user command
@thuan1412 thuan1412 changed the title Feat/enhance cycle forward function feat: enhance cycle forward function Jun 14, 2026
@dmtrKovalenko dmtrKovalenko marked this pull request as ready for review June 15, 2026 04:08
@dmtrKovalenko

Copy link
Copy Markdown
Owner

@gustav-fff fix the merge conflict here

Resolve merge conflict in lua/fff/picker_ui/picker_ui.lua by adopting
upstream's unified resume_state table and close_active_for_resume()
helper, while preserving the cycle-forward feature.
@gustav-fff

Copy link
Copy Markdown
Collaborator

[triage-bot] DIRECTED: cannot push to fork (cross-repo PR), resolution diff below.

Conflict is in lua/fff/picker_ui/picker_ui.lua only. main (#602) consolidated the three resume locals into a single resume_state table and replaced the active-picker guard with close_active_for_resume(). This branch kept the older shape and added a get_base_path capture in M.close(). Resolution: take main's structural rewrite, keep this PR's get_base_path snapshot, drop the old last_*_picker_state / last_closed_mode locals.

Run on this branch:

git fetch origin main
git merge origin/main

Then in lua/fff/picker_ui/picker_ui.lua keep these regions exactly:

--- @class fff.ResumeState
--- @field files table|nil Snapshot from last find_files session
--- @field grep table|nil Snapshot from last live_grep session
--- @field last_mode 'files'|'grep'|nil Mode of the most recently closed picker
local resume_state = { files = nil, grep = nil, last_mode = nil }
function M.close()
  if M.state.query == '' then
    layout_manager.close()
    return
  end
  if not M.state.active then return end

  local snapshot = vim.deepcopy(M.state)

  local fuzzy = require('fff.core').ensure_initialized()
  local ok, base_path = pcall(fuzzy.get_base_path)
  if ok and base_path then
    snapshot.base_path = base_path
  else
    snapshot.base_path = M.state.config and M.state.config.base_path or nil
  end

  if M.state.mode == 'grep' then
    resume_state.grep = snapshot
    resume_state.last_mode = 'grep'
  else
    resume_state.files = snapshot
    resume_state.last_mode = 'files'
  end

  layout_manager.close()
end

For M.resume, M.resume_find_files, M.resume_live_grep: take main's versions verbatim (the ones using close_active_for_resume() and resume_state.files / resume_state.grep / resume_state.last_mode). Drop all references to last_file_picker_state, last_grep_picker_state, last_closed_mode.

search_manager.lua from this PR (1ea1263) does not conflict.

Honk-Honk 🪿

@thuan1412

Copy link
Copy Markdown
Contributor Author

Hey @dmtrKovalenko , i've resolved the conflict

@dmtrKovalenko dmtrKovalenko merged commit eb11bb5 into dmtrKovalenko:main Jun 16, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants