fix(ui): delete moves to trash by default; n cancels yes/no dialogs (U-P0-4)
- F8 dialog defaults to the trash; permanent deletion only via D/d - n/N closes confirm and archive-type dialogs, as their notes promise - behavior.confirm_delete=false now works, and only skips the question for the trash (remote and permanent deletes still ask) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8d6fe48536
commit
f57565989c
2 changed files with 98 additions and 5 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"vcom/internal/config"
|
||||
vfs "vcom/internal/fs"
|
||||
"vcom/internal/testutil/teadriver"
|
||||
)
|
||||
|
|
@ -229,3 +230,78 @@ func TestNP115_ArchiveUnpackBlockedWithSSHPane(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func trashFiles(t *testing.T) string {
|
||||
t.Helper()
|
||||
return filepath.Join(os.Getenv("HOME"), ".local", "share", "Trash", "files")
|
||||
}
|
||||
|
||||
// U-P0-4: Enter in the delete dialog deleted permanently by default.
|
||||
func TestUP04_DeleteDefaultsToTrash(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeFile(t, filepath.Join(dir, "doc.txt"), "draft")
|
||||
d := newDriver(t, dir, t.TempDir())
|
||||
selectName(t, d, "doc.txt")
|
||||
d.Press("f8")
|
||||
d.Settle(settle)
|
||||
if !d.ScreenContains("trash") {
|
||||
t.Fatalf("dialog should say the file goes to the trash:\n%s", d.Screen())
|
||||
}
|
||||
d.Press("enter")
|
||||
d.Settle(settle)
|
||||
if exists(filepath.Join(dir, "doc.txt")) {
|
||||
t.Fatal("doc.txt not removed")
|
||||
}
|
||||
b, err := os.ReadFile(filepath.Join(trashFiles(t), "doc.txt"))
|
||||
if err != nil || string(b) != "draft" {
|
||||
t.Fatalf("doc.txt not in trash: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUP04_PermanentIsExplicit(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeFile(t, filepath.Join(dir, "junk.txt"), "x")
|
||||
d := newDriver(t, dir, t.TempDir())
|
||||
selectName(t, d, "junk.txt")
|
||||
d.Press("f8", "D")
|
||||
if !d.ScreenContains("Permanently delete") {
|
||||
t.Fatalf("D should switch to permanent mode:\n%s", d.Screen())
|
||||
}
|
||||
d.Press("enter")
|
||||
d.Settle(settle)
|
||||
if exists(filepath.Join(dir, "junk.txt")) || exists(filepath.Join(trashFiles(t), "junk.txt")) {
|
||||
t.Fatal("permanent delete should neither keep nor trash the file")
|
||||
}
|
||||
}
|
||||
|
||||
// U-P0-4: "n" did not close the dialog although the note promised it.
|
||||
func TestUP04_NCancels(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeFile(t, filepath.Join(dir, "keep.txt"), "x")
|
||||
d := newDriver(t, dir, t.TempDir())
|
||||
selectName(t, d, "keep.txt")
|
||||
d.Press("f8")
|
||||
if cur(t, d).modal.kind != modalConfirm {
|
||||
t.Fatal("delete dialog did not open")
|
||||
}
|
||||
d.Press("n")
|
||||
d.Settle(settle)
|
||||
if k := cur(t, d).modal.kind; k != modalNone {
|
||||
t.Fatalf("n did not close the dialog (modal %d)", k)
|
||||
}
|
||||
if !exists(filepath.Join(dir, "keep.txt")) {
|
||||
t.Fatal("n deleted the file")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUP04_NoConfirmOnlyForTrash(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeFile(t, filepath.Join(dir, "a.txt"), "x")
|
||||
d := newDriver(t, dir, t.TempDir(), func(c *config.Config) { c.Behavior.ConfirmDelete = false })
|
||||
selectName(t, d, "a.txt")
|
||||
d.Press("f8")
|
||||
d.Settle(settle)
|
||||
if exists(filepath.Join(dir, "a.txt")) || !exists(filepath.Join(trashFiles(t), "a.txt")) {
|
||||
t.Fatal("confirm_delete=false should move straight to the trash")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1339,7 +1339,7 @@ func (m Model) handleModalKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||
|
||||
case modalConfirm:
|
||||
switch {
|
||||
case isModalCloseKey(msg, m.keys):
|
||||
case isModalCloseKey(msg, m.keys), isModalNoKey(msg):
|
||||
log.Printf("[MODAL] Confirm — cancelled (Esc)")
|
||||
m.modal = modalState{}
|
||||
m.status = "Cancelled"
|
||||
|
|
@ -1458,7 +1458,7 @@ func (m Model) handleModalKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||
|
||||
case modalArchiveType:
|
||||
switch {
|
||||
case isModalCloseKey(msg, m.keys):
|
||||
case isModalCloseKey(msg, m.keys), isModalNoKey(msg):
|
||||
log.Printf("[MODAL] Archive — cancelled (Esc)")
|
||||
m.modal = modalState{}
|
||||
m.status = "Cancelled"
|
||||
|
|
@ -1652,6 +1652,12 @@ func (m Model) handleModalKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
// isModalNoKey is the "n" answer of yes/no dialogs (their notes promise
|
||||
// "Esc / n to cancel"). Not used by dialogs with text input.
|
||||
func isModalNoKey(msg tea.KeyMsg) bool {
|
||||
return msg.String() == "n" || msg.String() == "N"
|
||||
}
|
||||
|
||||
func isModalCloseKey(msg tea.KeyMsg, keys KeyMap) bool {
|
||||
return key.Matches(msg, keys.Cancel) || msg.String() == "q"
|
||||
}
|
||||
|
|
@ -2462,11 +2468,22 @@ func (m *Model) handleDelete() (tea.Model, tea.Cmd) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
// Default to permanent delete
|
||||
m.deleteKind = "permanent"
|
||||
// Default to the trash; permanent deletion is an explicit choice (D/d
|
||||
// in the dialog). U-P0-4.
|
||||
m.deleteKind = "trash"
|
||||
|
||||
// behavior.confirm_delete=false skips the question, but only for the
|
||||
// recoverable trash path.
|
||||
if !m.cfg.Behavior.ConfirmDelete {
|
||||
if m.archiveJob != nil {
|
||||
m.status = "Delete is already running"
|
||||
return m, nil
|
||||
}
|
||||
return m, m.startDeleteJob(opDelete, sources)
|
||||
}
|
||||
|
||||
// Show confirm dialog with mode toggle (no plan — skip counting files)
|
||||
title := "Permanently delete selected entr" + pluralSuffix(len(sources), "y", "ies") + "?"
|
||||
title := "Move selected entr" + pluralSuffix(len(sources), "y", "ies") + " to trash?"
|
||||
body := fmt.Sprintf("Items: %d", len(sources))
|
||||
note := fmt.Sprintf("Mode: %s (D/d to change)\nEnter / y to confirm, Esc / n to cancel", m.deleteKind)
|
||||
m.openConfirmModal(title, body, note, pendingOperation{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue