1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-14 18:47:28 +00:00

feat(analyze): add multi-select for batch file operations

- Add spacebar to toggle selection on files/directories
- Support batch delete for multiple selected items
- Support batch open (O) and reveal in Finder (F) for selections
- Show selection count and total size in status bar
- Display selection indicator (● selected, ○ unselected)
- Clear selections when navigating directories or switching views

Closes #137
This commit is contained in:
Jon Loinaz
2025-12-19 18:27:21 +01:00
parent e1574ec35e
commit 7ed3c9e75a
4 changed files with 360 additions and 60 deletions

View File

@@ -4,6 +4,7 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
"sync/atomic"
tea "github.com/charmbracelet/bubbletea"
@@ -21,6 +22,54 @@ func deletePathCmd(path string, counter *int64) tea.Cmd {
}
}
// deleteMultiplePathsCmd deletes multiple paths and returns combined results
func deleteMultiplePathsCmd(paths []string, counter *int64) tea.Cmd {
return func() tea.Msg {
var totalCount int64
var errors []string
for _, path := range paths {
count, err := deletePathWithProgress(path, counter)
totalCount += count
if err != nil {
errors = append(errors, err.Error())
}
}
var resultErr error
if len(errors) > 0 {
resultErr = &multiDeleteError{errors: errors}
}
// Return empty path to trigger full refresh since multiple items were deleted
return deleteProgressMsg{
done: true,
err: resultErr,
count: totalCount,
path: "", // Empty path signals multiple deletions
}
}
}
// multiDeleteError holds multiple deletion errors
type multiDeleteError struct {
errors []string
}
func (e *multiDeleteError) Error() string {
if len(e.errors) == 1 {
return e.errors[0]
}
return strings.Join(e.errors[:min(3, len(e.errors))], "; ")
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func deletePathWithProgress(root string, counter *int64) (int64, error) {
var count int64
var firstErr error