How Selection Mode Works for Multi-File Operations in Superfile
Superfile’s selection mode transforms the file panel into a check-list interface that stores selected paths in a map-backed registry, enabling bulk copy, move, delete, and compress operations with single keystrokes.
Superfile is a terminal-based file manager that eliminates repetitive strain by letting you queue multiple files for action. The selection mode multi-file operations capability is the core mechanism that switches the interface from single-item navigation to a multi-select checklist. According to the yorukot/superfile source code, this mode is governed by a state machine that tracks selected paths in an ordered map, which bulk operation handlers consume instead of the single cursor target.
Entering and Exiting Selection Mode
The transition between normal browsing and multi-select is triggered by the v key, defined in src/internal/ui/helpmenu/data.go as the binding for “Change between selection mode or normal mode”.
Internally, the panel state is represented by constants declared in src/internal/ui/filepanel/consts.go:
const (
BrowserMode = iota // normal navigation
SelectMode // checkbox-style multi-select
)
When the user presses v, the application toggles between these states. Exiting selection mode—either by pressing v again or hitting Esc—invokes ClearSelection(), which empties the registry and returns the panel to BrowserMode. The state also resets automatically when the panel loses focus or an operation completes, preventing stale selections from leaking into subsequent commands.
How Selected Files Are Tracked Internally
Selections are stored in a dedicated map defined in src/internal/ui/filepanel/types.go. The field selection map[string]int uses the absolute file path as the key and an integer as the value to preserve the selection order.
This design allows Superfile to maintain a stable queue of targets without duplicating file handles in memory. The order integer ensures that range selections and “select all” operations respect the visual sequence of the file list.
Key Bindings for Managing Selections
Once in SelectMode, the following inputs modify the selection map:
- Space – Toggles the item under the cursor. The logic lives in
src/internal/ui/filepanel/utils.goinside functions likeSelectItem, which either inserts the path withlen(p.Selection) + 1as the order or deletes the existing entry. - Shift + Space – Extends the selection from the last-selected index to the current cursor position, creating a contiguous block.
- a – Selects every visible item in the panel by invoking
SelectAllinsrc/internal/ui/filepanel/update.go. This only functions when the panel is already inSelectMode. - Esc or v – Clears the map and returns to
BrowserMode.
The UI can optionally render checkboxes next to each entry when the ShowSelectIcons boolean (configured in src/internal/common/config_type.go) is enabled.
Executing Operations on Selected Files
Bulk actions are handled by the operation layer in src/internal/handle_file_operations.go. Before executing a command, the handler checks if the selection map is non-empty; if so, it iterates over the map keys rather than acting on the single highlighted item.
Supported operations include:
- c – Copy selected files to the opposite panel’s current directory.
- m – Move selected files to the opposite panel.
- d – Delete all selected entries after confirmation.
- z – Compress the selected set into an archive.
Each operation constructs a slice of paths from the map keys, then passes that slice to the relevant filesystem driver. After the operation finishes, Superfile automatically clears the selection to prevent accidental reuse.
Code Example: Selection Workflow
The following Go snippets illustrate the toggle logic and bulk execution flow found in the source:
// Toggle between BrowserMode and SelectMode
func toggleSelectMode(p *Panel) {
if p.Mode == BrowserMode {
p.Mode = SelectMode
} else {
p.Mode = BrowserMode
p.ClearSelection()
}
}
// Toggle the current item under the cursor (Space key)
func (p *Panel) SelectCurrent() {
cur := p.Cursor()
if _, ok := p.Selection[cur.Path]; ok {
delete(p.Selection, cur.Path) // un-select
} else {
p.Selection[cur.Path] = len(p.Selection) + 1 // add with order
}
}
// Execute a bulk copy using the selection map
func (p *Panel) CopySelected(dst string) error {
files := make([]string, 0, len(p.Selection))
for path := range p.Selection {
files = append(files, path)
}
return fileOps.Copy(files, dst)
}
Summary
- Superfile uses a
map[string]intinsrc/internal/ui/filepanel/types.goto track selected paths and their order. - Press
vto toggleSelectMode; useSpaceto toggle individual items andato select all. - Bulk operations (
c,m,d,z) insrc/internal/handle_file_operations.goconsume the selection map when it is non-empty. - The selection auto-clears on panel focus loss or after an operation, ensuring predictable state management.
- Enable
ShowSelectIconsin the configuration to render checkbox indicators in the UI.
Frequently Asked Questions
How do I enter selection mode in Superfile?
Press the v key. This toggles the file panel from BrowserMode to SelectMode, enabling checkbox-style multi-select as defined in src/internal/ui/filepanel/consts.go.
Where does Superfile store the list of selected files?
The application stores selections in a map field named selection inside the panel struct, declared in src/internal/ui/filepanel/types.go. The map uses file paths as keys and integers as values to preserve selection order.
Can I select a range of files without clicking each one individually?
Yes. Hold Shift and press Space to extend the selection from the last-selected item to the current cursor position, creating a contiguous block.
What happens to my selection after I copy or delete the files?
Superfile automatically clears the selection map and returns the panel to BrowserMode once the operation completes. This behavior prevents stale selections from persisting and accidentally affecting subsequent commands.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →