-
Notifications
You must be signed in to change notification settings - Fork 447
feat(fff-nvim): add clear_query picker action #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,6 +318,19 @@ function M.recall_query_from_history() | |
| end) | ||
| end | ||
|
|
||
| function M.clear_query() | ||
| if not P.state.active then return end | ||
|
|
||
| S.history_offset = nil | ||
| vim.api.nvim_buf_set_lines(S.input_buf, 0, -1, false, { S.config.prompt }) | ||
|
|
||
| vim.schedule(function() | ||
| if P.state.active and S.input_win and vim.api.nvim_win_is_valid(S.input_win) then | ||
| vim.api.nvim_win_set_cursor(S.input_win, { 1, #S.config.prompt }) | ||
| end | ||
| end) | ||
|
Comment on lines
+321
to
+331
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- target function ---'
sed -n '280,360p' lua/fff/picker_ui/search_manager.lua
printf '%s\n' '--- public API references ---'
rg -n --glob '*.lua' 'clear_query|search_manager' .
printf '%s\n' '--- focus and mode helpers ---'
rg -n --glob '*.lua' 'set_current_win|nvim_set_current_win|nvim_win_set_cursor|startinsert|input_win|input_buf' lua | head -240
printf '%s\n' '--- module function documentation patterns ---'
sed -n '1,120p' lua/fff/picker_ui/search_manager.lua
rg -n --glob '*.lua' '---@param|---@return|---@alias|---@class' lua/fff | head -160Repository: dmtrKovalenko/fff Length of output: 17857 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- picker API wiring and callers ---'
sed -n '1,80p' lua/fff/picker_ui/picker_ui.lua
sed -n '150,215p' lua/fff/picker_ui/picker_ui.lua
sed -n '270,310p' lua/fff/picker_ui/picker_ui.lua
sed -n '630,685p' lua/fff/picker_ui/picker_ui.lua
printf '%s\n' '--- keymaps and focus implementation ---'
sed -n '320,390p' lua/fff/picker_ui/ui_creator.lua
sed -n '410,510p' lua/fff/picker_ui/ui_creator.lua
printf '%s\n' '--- API documentation and configuration ---'
rg -n --glob '*.lua' --glob '*.md' 'clear_query|focus_input_win|keymaps|prompt_position' README.md luaRepository: dmtrKovalenko/fff Length of output: 28258 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
search = Path("lua/fff/picker_ui/search_manager.lua").read_text()
ui = Path("lua/fff/picker_ui/ui_creator.lua").read_text()
picker = Path("lua/fff/picker_ui/picker_ui.lua").read_text()
m = re.search(r"function M\.clear_query\(\)(.*?)\nend", search, re.S)
assert m, "M.clear_query was not found"
body = m.group(1)
print("clear_query_calls_set_current_win:", "nvim_set_current_win" in body)
print("clear_query_calls_startinsert:", "startinsert" in body)
print("clear_query_sets_input_cursor:", "nvim_win_set_cursor(S.input_win" in body)
print("picker_exports_clear_query:", "M.clear_query = search_manager.clear_query" in picker)
focus = re.search(r"function M\.focus_input_win\(\)(.*?)\nend", ui, re.S)
assert focus, "M.focus_input_win was not found"
focus_body = focus.group(1)
print("focus_input_win_sets_current_win:", "nvim_set_current_win(S.input_win)" in focus_body)
print("focus_input_win_starts_insert:", "startinsert!" in focus_body)
assert "nvim_set_current_win" not in body
assert "startinsert" not in body
assert "nvim_win_set_cursor(S.input_win" in body
assert "M.clear_query = search_manager.clear_query" in picker
assert "nvim_set_current_win(S.input_win)" in focus_body
assert "startinsert!" in focus_body
PYRepository: dmtrKovalenko/fff Length of output: 377 Focus the input window in 🤖 Prompt for AI Agents |
||
| end | ||
|
|
||
| function M.cycle_forward_query() | ||
| if not P.state.active then return end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -389,6 +389,8 @@ function M.setup_keymaps() | |
| set_keymap({ 'i', 'n' }, keymaps.toggle_select, P.toggle_select, input_opts) | ||
| set_keymap({ 'i', 'n' }, keymaps.send_to_quickfix, P.send_to_quickfix, input_opts) | ||
| set_keymap({ 'i', 'n' }, keymaps.cycle_grep_modes, P.cycle_grep_modes, input_opts) | ||
| -- last, so an explicitly configured key wins over the built-in bound to it | ||
| set_keymap('i', keymaps.clear_query, P.clear_query, input_opts) | ||
|
Comment on lines
+392
to
+393
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
file="lua/fff/picker_ui/ui_creator.lua"
printf '%s\n' '--- target section ---'
sed -n '350,425p' "$file"
printf '%s\n' '--- keymap definitions and uses ---'
rg -n -C 3 'insert_newline_escape|clear_query|set_keymap|prompt_position' lua/fff
printf '%s\n' '--- related tests/config/docs ---'
rg -n -C 2 'insert_newline_escape|clear_query|prompt_position' . \
-g '*.lua' -g '*.md' -g '*.vim' -g '*.json' -g '*.yaml' -g '*.yml' \
--glob '!vendor/**' --glob '!node_modules/**'Repository: dmtrKovalenko/fff Length of output: 50373 🏁 Script executed: #!/bin/bash
set -eu
file="lua/fff/picker_ui/ui_creator.lua"
printf '%s\n' '--- set_keymap implementation ---'
sed -n '65,115p' "$file"
printf '%s\n' '--- clear_query implementation ---'
sed -n '300,345p' lua/fff/picker_ui/search_manager.lua
printf '%s\n' '--- configuration validation ---'
rg -n -C 5 'keymaps|insert_newline_escape|clear_query|validate' lua/fff/conf.lua lua/fff
printf '%s\n' '--- focused tests and test tooling ---'
find tests -maxdepth 2 -type f -print | sort
rg -n -C 3 'keymap|clear_query|newline_escape|prompt_position' tests README.md
printf '%s\n' '--- Neovim availability ---'
command -v nvim || true
nvim --version 2>/dev/null | head -n 2 || trueRepository: dmtrKovalenko/fff Length of output: 39879 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
path = Path("lua/fff/picker_ui/ui_creator.lua")
text = path.read_text()
clear = text.index("set_keymap('i', keymaps.clear_query, P.clear_query, input_opts)")
newline = text.index("set_keymap('i', keymaps.insert_newline_escape,", clear)
assert clear < newline, "mapping order changed"
# Both mappings use the same mode and the same buffer options.
assert "set_keymap('i', keymaps.clear_query, P.clear_query, input_opts)" in text
assert "set_keymap('i', keymaps.insert_newline_escape, function()" in text
assert "buffer = S.input_buf" in text[text.index("function M.setup_keymaps"):text.index("function M.setup_keymaps") + 500]
# Model the relevant registration order for equal configured keys.
maps = [
("i", "clear_query", "P.clear_query"),
("i", "insert_newline_escape", "expr handler"),
]
effective = {}
for mode, key, handler in maps:
effective[(mode, key)] = handler
assert effective[("i", "clear_query")] == "expr handler"
# Prompt position is resolved by layout code, not by setup_keymaps.
setup = text[text.index("function M.setup_keymaps"):text.index("function M.setup_keymaps") + 12000]
assert "prompt_position" not in setup
print("clear_query registration precedes insert_newline_escape")
print("equal insert-mode keys leave insert_newline_escape as the effective mapping")
print("setup_keymaps is independent of prompt_position; the collision applies to top and bottom layouts")
PYRepository: dmtrKovalenko/fff Length of output: 244 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
path = Path("lua/fff/picker_ui/ui_creator.lua")
lines = path.read_text().splitlines()
start = next(i for i, line in enumerate(lines) if line == "function M.setup_keymaps()")
end = next(i for i in range(start, len(lines)) if lines[i] == " -- List buffer")
setup = lines[start:end]
clear_i = next(i for i, line in enumerate(setup) if "keymaps.clear_query" in line)
newline_i = next(i for i, line in enumerate(setup) if "keymaps.insert_newline_escape" in line)
newline_handler_i = next(i for i, line in enumerate(setup) if "if S.mode ~= 'grep' then return '' end" in line)
assert clear_i < newline_i
assert "input_opts = { buffer = S.input_buf" in "\n".join(setup)
assert "set_keymap('i', keymaps.clear_query, P.clear_query, input_opts)" in setup[clear_i]
assert "set_keymap('i', keymaps.insert_newline_escape, function()" in setup[newline_i]
assert setup[newline_handler_i].strip() == "if S.mode ~= 'grep' then return '' end"
assert not any("prompt_position" in line for line in setup)
# Registration order for equal mode/buffer/lhs keys: the later mapping is effective.
registrations = ["clear_query", "insert_newline_escape"]
effective = registrations[-1]
assert effective == "insert_newline_escape"
print("registration order: clear_query < insert_newline_escape")
print("both mappings: insert mode + input buffer")
print("non-grep newline handler result: empty string")
print("setup_keymaps has no prompt_position branch")
print("effective mapping for equal configured keys: insert_newline_escape")
PYRepository: dmtrKovalenko/fff Length of output: 244 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
lines = Path("lua/fff/picker_ui/ui_creator.lua").read_text().splitlines()
start = next(i for i, line in enumerate(lines) if line == "function M.setup_keymaps()")
end = next(i for i in range(start, len(lines)) if lines[i] == " -- List buffer")
setup = lines[start:end]
clear_i = next(i for i, line in enumerate(setup) if "set_keymap('i', keymaps.clear_query," in line)
newline_i = next(i for i, line in enumerate(setup) if "set_keymap('i', keymaps.insert_newline_escape," in line)
handler_i = next(i for i, line in enumerate(setup) if "if S.mode ~= 'grep' then return '' end" in line)
checks = {
"clear precedes newline": clear_i < newline_i,
"clear uses input_opts": setup[clear_i].endswith("input_opts)"),
"newline uses input mapping": setup[newline_i].startswith(" set_keymap('i', keymaps.insert_newline_escape,"),
"non-grep return is empty": setup[handler_i].strip() == "if S.mode ~= 'grep' then return '' end",
"input buffer option exists": any("input_opts = { buffer = S.input_buf" in line for line in setup),
}
for name, ok in checks.items():
print(f"{name}: {ok}")
if not ok:
print(" clear:", setup[clear_i])
print(" newline:", setup[newline_i])
print(" handler:", setup[handler_i])
raise SystemExit(1)
print("equal insert-mode keys are registered with clear_query first and insert_newline_escape second")
print("prompt_position is not referenced by setup_keymaps")
PYRepository: dmtrKovalenko/fff Length of output: 454 Register When both options use the same insert-mode key, the later expression mapping replaces 🤖 Prompt for AI AgentsSources: Coding guidelines, MCP tools |
||
|
|
||
| if keymaps.insert_newline_escape then | ||
| -- Inserts the literal 2-char `\n` sequence which the grep engine | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: dmtrKovalenko/fff
Length of output: 2306
🏁 Script executed:
Repository: dmtrKovalenko/fff
Length of output: 28599
Add
---@return nilbeforeM.clear_query. Keep the exported function typed asfun(): nil.🤖 Prompt for AI Agents
Source: Coding guidelines