diff options
author | Joe <rbo@gmx.us> | 2024-01-15 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-01-15 20:20:20 +0100 |
commit | 0d4ed52f7dc666b8ad36519520328aea623ffba1 (patch) | |
tree | 4813050c97c7853720fd6f73ae32de23f8ea1f35 /i_events.go | |
parent | think its ok (diff) | |
download | hardflip-0d4ed52f7dc666b8ad36519520328aea623ffba1.tar.gz hardflip-0d4ed52f7dc666b8ad36519520328aea623ffba1.tar.bz2 hardflip-0d4ed52f7dc666b8ad36519520328aea623ffba1.tar.xz hardflip-0d4ed52f7dc666b8ad36519520328aea623ffba1.tar.zst hardflip-0d4ed52f7dc666b8ad36519520328aea623ffba1.zip |
delete boy
Diffstat (limited to 'i_events.go')
-rw-r--r-- | i_events.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/i_events.go b/i_events.go index 23d2db3..d1cd8e4 100644 --- a/i_events.go +++ b/i_events.go @@ -76,7 +76,7 @@ func i_list_follow_cursor(litems *ItemsList, ui *HardUI) { func i_set_unfold(data *HardData, item *ItemsNode) { delete(data.folds, item.Dirs) - for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next { + for ptr := data.litems.head; ptr != nil && ptr.next != nil; ptr = ptr.next { ptr.next.ID = ptr.ID + 1 } } @@ -124,7 +124,7 @@ func i_set_fold(data *HardData, curr, start, end *ItemsNode) { } folds[curr.Dirs] = &tmp - for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next { + for ptr := data.litems.head; ptr != nil && ptr.next != nil; ptr = ptr.next { ptr.next.ID = ptr.ID + 1 } } @@ -180,13 +180,16 @@ func i_delete_dir(data *HardData) { return } curr := data.litems.curr + dir_path := data.data_dir + data.litems.curr.Dirs.path() if data.folds[curr.Dirs] == nil { i_fold_dir(data, curr) } delete(data.folds, curr.Dirs) if curr == data.litems.head { data.litems.head = curr.next - curr.next.prev = nil + if curr.next != nil { + curr.next.prev = nil + } if data.litems.draw == curr { data.litems.draw = curr.next } @@ -200,23 +203,13 @@ func i_delete_dir(data *HardData) { data.litems.last = curr.prev data.litems.curr = curr.prev } - for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next { + for ptr := data.litems.head; ptr != nil && ptr.next != nil; ptr = ptr.next { ptr.next.ID = ptr.ID + 1 } - // dir_path := data.data_dir + dir.path() - // if err := os.RemoveAll(dir_path); err != nil { - // data.ui.s.Fini() - // c_die("can't remove " + dir_path, err) - // } - // TODO: delete folds map reference if folded - OK - // TEST: single empty dir OK - // TEST: single non-empty dir OK - // TEST: first dir OK - // TEST: first dir is also head - // TEST: last dir - // TEST: last dir is also last - // TEST: last dir 4m+ - // TEST: folded + if err := os.RemoveAll(dir_path); err != nil { + data.ui.s.Fini() + c_die("can't remove " + dir_path, err) + } } func i_delete_host(data *HardData) { @@ -298,8 +291,7 @@ func i_events(data *HardData) { event.Key() == tcell.KeyEnd { data.litems.curr = data.litems.last } else if event.Rune() == 'D' && - data.ldirs.head != nil && - ui.sel_max != 0 { + data.ldirs.head != nil { ui.mode = DELETE_MODE } else if event.Key() == tcell.KeyEnter { if data.litems.curr == nil { @@ -348,6 +340,14 @@ func i_events(data *HardData) { } else if event.Rune() == 'y' { i_delete_host(data) ui.mode = NORMAL_MODE + // data.ui.s.Fini() + // fmt.Println( + // "head:", data.litems.head, + // "\nlast:", data.litems.last, + // "\ncurr:", data.litems.curr, + // "\ndraw:", data.litems.draw, + // ) + // os.Exit(0) } } } |