feat: add smart autocomplete for command execution and path navigation#6
Conversation
…es for empty base
- Add Ctrl+R command execution dialog with path/command autocomplete - Add Ctrl+G Go to path dialog with directory-only suggestions - Implement multi-line compact suggestion display (multiple items per line) - Add Tab completion with smart prefix matching and common prefix expansion - Support tilde (~) expansion for home directory paths - Display suggestion basenames for better readability - Add exec-only mode toggle in command overlay (Ctrl+G) - Update documentation and configuration examples - Format code with gofmt for consistency
There was a problem hiding this comment.
Good addition, a couple of improvements points:
- The PR adds
NewInputWithBase(title, message, defaultValue, tag, basePath string)and refactors NewInput to delegate to it with basePath: "". However, app.go:644 still calls dialog.NewInput(...), so basePath is always "". When completeDialogPathCandidates resolves relative paths, filepath.Join("", ".") gives the process working directory — not the active panel's directory. Autocomplete will show completions relative to wherever mdc was launched from. - code duplication between cmdexec and dialog
- expandTilde() — identical in both files
- commonPrefix() — identical in both files
- formatSuggestions() / formatDialogSuggestions() — same logic, different names
- completePathCandidates() / completeDialogPathCandidates() — nearly identical (dialog version filters dirs-only)
- padOrTrim() / truncOrPad() — same logic, different names
Let's move them to a shared lib.
- updateSuggestions() (which calls os.ReadDir) fires on cursor movement keys (left/right/home/end) even though the input text didn't change
- PATH scanning (completeExecCandidates) runs on every keystroke with no caching
- No bounds checking in completeCurrentWord cursor positioning in internal/ui/cmdexec/cmdexec.go:349-362
m.inputPos = clamp(start+len(common)-(end-m.inputPos), len(m.input))
The expression start+len(common)-(end-m.inputPos) can produce unexpected values when end > m.inputPos (which happens when the cursor is in the middle of a word). The clamp function saves it from going out of bounds, but the cursor may jump to an incorrect position after completion when the cursor isn't at the end of the word.
6. execOnly mode has no visual indicator and no way to toggle off
7. Ctrl+G keybinding conflict: inside the command execution overlay, Ctrl+G is repurposed to toggle "exec-only mode" (m.execOnly = true). But Ctrl+G is already the global keybinding for "Go To path.". Let's perhaps pick another keybinding to avoid a confusion.
Review Comment ResponseSummaryImplemented the smart autocomplete refactor, fixed command execution overlay behavior, and resolved the Fixes Applied
Review Comment Responses
Validation
|
kooler
left a comment
There was a problem hiding this comment.
Thanks for the update, just one small issue left: code duplication persists in dialog.go despite shared completion package. The shared package now provides CompletePathCandidates(prefix, dir, dirsOnly), CommonPrefix, FormatSuggestions, and PadOrTrim. However, dialog.go still contains its own local copies that don't delegate to the shared package.
|
Addressed |
Smart Autocomplete for Command Execution and Path Navigation
Overview
This PR adds intelligent autocomplete functionality to Midday Commander, enhancing the user experience when executing commands and navigating directories through two new dialog modes.
Features
🎯 Command Execution Dialog (Ctrl+R)
~expansion to home directory📁 Go to Path Dialog (Ctrl+G)
🎨 User Experience Improvements
Technical Implementation
Core Components Modified
internal/ui/cmdexec/cmdexec.go: Command execution overlay with autocompleteinternal/ui/dialog/dialog.go: Go to path dialog with directory suggestionsREADME.md: Updated documentation and keybindingsconfig.example.toml: Added configuration examplesKey Functions Added
completeCandidates(): Unified completion logic for paths and executablesformatSuggestions(): Multi-line suggestion formattingexpandTilde(): Home directory expansioncompleteDialogPathCandidates(): Directory-only path completionformatDialogSuggestions(): Compact dialog suggestion displayCode Quality
gofmtgo vetchecksUsage Examples
Command Execution (Ctrl+R)
Path Navigation (Ctrl+G)
Tilde Expansion
Configuration
The new keybindings can be customized in
config.toml:Testing
Screenshots
Command Execution Dialog
Go to Path Dialog
Breaking Changes
None. This is a purely additive feature that doesn't change existing behavior.