Skip to content

All going back to categories - #41

Merged
nikero41 merged 2 commits into
mainfrom
command-palette-improvements
Mar 29, 2026
Merged

All going back to categories#41
nikero41 merged 2 commits into
mainfrom
command-palette-improvements

Conversation

@nikero41

Copy link
Copy Markdown
Owner

This pull request enhances the CommandPalette in lua/nikero/command_palette.lua by improving the user experience when navigating and selecting commands, particularly by adding a "back" functionality and customizing keybindings and layout. The most important changes are grouped below:

Navigation and UX improvements:

  • The select_command method now accepts an on_back callback, enabling users to go back to the previous menu (e.g., the category list) when pressing backspace or a specific key combination. [1] [2]
  • Added a go_back function and integrated it into the command picker, so that pressing <BS> (backspace) or <C-h> (Ctrl+H) in either the input or list view will trigger the back action if the input is empty.
  • Customized the picker layout and focus using the snacks options to provide a more "VSCode-like" experience and ensure consistent navigation behavior.

Refactoring and API changes:

  • Updated the show method so that when a user navigates back from a command group, the category selection menu is shown again by passing a callback to select_command.

@coderabbitai

coderabbitai Bot commented Mar 29, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Command palette updated with a VS Code–style layout and improved list focus for faster navigation.
    • Backspace/Ctrl-h behavior is context-aware: deletes input when typing, or navigates back to categories when at empty input.
    • Returning from a command picker reliably restores the category view for seamless back-and-forth navigation.

Walkthrough

CommandPalette.select_command gained an on_back callback and now uses Snacks-configured vim.ui.select (layout "vscode", focus "list") with context-aware <BS>/<C-h> handling to support back navigation from the command picker to the category picker.

Changes

Cohort / File(s) Summary
Command Palette
lua/nikero/command_palette.lua
Changed select_command(commands)select_command(commands, on_back). Switched picker to Snacks layout ("vscode", focus="list"). Added input-aware <BS>/<C-h> bindings: delete when input non-empty, close-and-call on_back otherwise; list bindings close-and-call on_back. show now passes an on_back that re-invokes the category picker. Selection now guards against nil selection before executing command.

Sequence Diagram

sequenceDiagram
    actor User
    participant CategoryPicker as "Category Picker"
    participant CommandPicker as "Command Picker"
    participant Snacks as "Snacks UI"

    User->>CategoryPicker: open CommandPalette
    Snacks->>CategoryPicker: render (layout: vscode, focus:list)
    User->>CategoryPicker: select category
    CategoryPicker->>CommandPicker: select_command(commands, on_back)
    Snacks->>CommandPicker: render (layout: vscode, focus:list)
    alt User presses BS/C-h with empty input
        User->>CommandPicker: BS/C-h
        CommandPicker->>Snacks: close picker
        CommandPicker->>CategoryPicker: call on_back (re-open)
        Snacks->>CategoryPicker: render
    else User deletes character (input non-empty)
        User->>CommandPicker: BS/C-h (delete)
    end
    opt User selects a command
        User->>CommandPicker: select item
        CommandPicker->>CommandPicker: if not nil then execute (fn or vim.cmd)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through choices, soft and quick,
Pressed back with paws — a clever trick,
From commands to categories I glide,
Snacks lights the path where I can hide.
Cheers for loops that let me bounce!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'All going back to categories' accurately summarizes the main feature added: back navigation that returns users to the category menu from the command picker.
Description check ✅ Passed The description clearly relates to the changeset by detailing the back navigation functionality, on_back callback, keybinding customizations, and layout improvements added to the CommandPalette.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch command-palette-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lua/nikero/command_palette.lua (1)

102-109: Remove redundant nil checks.

After the guard on line 102, command is guaranteed to be non-nil, making the command and checks on lines 104 and 106 redundant.

♻️ Simplified conditionals
 	}, function(command)
 		if not command then return end
 
-		if command and type(command[2]) == "function" then
+		if type(command[2]) == "function" then
 			command[2]()
-		elseif command and type(command[2]) == "string" then
+		elseif type(command[2]) == "string" then
 			vim.cmd(command[2])
 		end
 	end)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/nikero/command_palette.lua` around lines 102 - 109, After the early
return "if not command then return end", remove the redundant nil checks in the
subsequent branches: replace "if command and type(command[2]) == 'function'
then" and "elseif command and type(command[2]) == 'string' then" with checks
that rely only on command[2] (e.g., "if type(command[2]) == 'function' then" and
"elseif type(command[2]) == 'string' then") so the logic uses the guaranteed
non-nil command and directly tests command[2]; keep the existing calls to
command[2]() and vim.cmd(command[2]) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lua/nikero/command_palette.lua`:
- Around line 102-109: After the early return "if not command then return end",
remove the redundant nil checks in the subsequent branches: replace "if command
and type(command[2]) == 'function' then" and "elseif command and
type(command[2]) == 'string' then" with checks that rely only on command[2]
(e.g., "if type(command[2]) == 'function' then" and "elseif type(command[2]) ==
'string' then") so the logic uses the guaranteed non-nil command and directly
tests command[2]; keep the existing calls to command[2]() and
vim.cmd(command[2]) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fbd0da90-bf40-47bb-930d-7229896c5298

📥 Commits

Reviewing files that changed from the base of the PR and between 1ecfda6 and f0370dc.

📒 Files selected for processing (1)
  • lua/nikero/command_palette.lua

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
lua/nikero/command_palette.lua (2)

112-121: Consider extracting shared Snacks layout config.

The { layout = { preset = "vscode" }, focus = "list" } options are duplicated between show (line 115) and select_command (lines 72-73). Consider extracting to a module-level constant:

local PICKER_LAYOUT = { layout = { preset = "vscode" }, focus = "list" }

Then merge into snacks_opts and use directly in show. This is minor—current code is perfectly functional.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/nikero/command_palette.lua` around lines 112 - 121, Extract the
duplicated snacks layout table into a module-level constant (e.g. local
PICKER_LAYOUT = { layout = { preset = "vscode" }, focus = "list" }) and replace
the inline tables in CommandPalette:show and CommandPalette:select_command by
merging or assigning this constant into their snacks_opts; update show to use
PICKER_LAYOUT (or vim.tbl_extend if you need to preserve other keys) instead of
the inline `{ layout = { preset = "vscode" }, focus = "list" }` so both
functions reference the same PICKER_LAYOUT symbol.

6-6: Type annotation should mark on_back as optional.

The implementation guards against nil on line 68, so the parameter is effectively optional. Consider updating the annotation:

----@field select_command fun(self: CommandPalette, commands: Command[], on_back: fun())
+---@field select_command fun(self: CommandPalette, commands: Command[], on_back?: fun())
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/nikero/command_palette.lua` at line 6, The type annotation for
CommandPalette.select_command marks the on_back parameter as required but the
implementation guards against nil, so make on_back optional in the signature;
update the annotation for select_command (the method on the CommandPalette type)
to accept on_back as an optional callback (e.g., allow nil) so it matches the
runtime guard around on_back in the implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lua/nikero/command_palette.lua`:
- Around line 74-78: The call picker.input:get() in the back_or_delete action is
invalid for Snacks.nvim; change the check to use the correct API (e.g., read the
current input line via picker.input.win:line() or the filter via
picker:filter.pattern) so the condition becomes "if current input is not empty
then return backspace"; update the back_or_delete function to use
picker.input.win:line() or picker:filter.pattern instead of picker.input:get().

---

Nitpick comments:
In `@lua/nikero/command_palette.lua`:
- Around line 112-121: Extract the duplicated snacks layout table into a
module-level constant (e.g. local PICKER_LAYOUT = { layout = { preset = "vscode"
}, focus = "list" }) and replace the inline tables in CommandPalette:show and
CommandPalette:select_command by merging or assigning this constant into their
snacks_opts; update show to use PICKER_LAYOUT (or vim.tbl_extend if you need to
preserve other keys) instead of the inline `{ layout = { preset = "vscode" },
focus = "list" }` so both functions reference the same PICKER_LAYOUT symbol.
- Line 6: The type annotation for CommandPalette.select_command marks the
on_back parameter as required but the implementation guards against nil, so make
on_back optional in the signature; update the annotation for select_command (the
method on the CommandPalette type) to accept on_back as an optional callback
(e.g., allow nil) so it matches the runtime guard around on_back in the
implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 75d20d5a-cd9c-484f-9c27-7ee30aea5e88

📥 Commits

Reviewing files that changed from the base of the PR and between f0370dc and cafa5ea.

📒 Files selected for processing (1)
  • lua/nikero/command_palette.lua

Comment thread lua/nikero/command_palette.lua
@nikero41
nikero41 merged commit 3972240 into main Mar 29, 2026
3 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.

1 participant