1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:04:42 +00:00

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

- 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

Authored-by: Sizk <sizk@users.noreply.github.com>
This commit is contained in:
Sizk
2025-12-21 22:10:06 +08:00
committed by Tw93
parent 6d087b3b12
commit 74d05ed9aa
4 changed files with 361 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