From 302ef8cfa60d2d7c6236e1dd7821750e4e1e8a47 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 15 Jan 2024 20:20:20 +0100 Subject: cleaner i guess --- c_litems.go | 9 +++++++++ i_events.go | 12 +++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/c_litems.go b/c_litems.go index 4aa21d6..86841ca 100644 --- a/c_litems.go +++ b/c_litems.go @@ -210,3 +210,12 @@ func (item *ItemsNode) get_next_level() *ItemsNode { } return nil } + +func (litems *ItemsList) reset_id() { + if litems.head != nil { + litems.head.ID = 1 + } + for ptr := litems.head; ptr != nil && ptr.next != nil; ptr = ptr.next { + ptr.next.ID = ptr.ID + 1 + } +} diff --git a/i_events.go b/i_events.go index ccc35b8..f1cf3c4 100644 --- a/i_events.go +++ b/i_events.go @@ -76,9 +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 != nil && ptr.next != nil; ptr = ptr.next { - ptr.next.ID = ptr.ID + 1 - } + data.litems.reset_id() } func i_unfold_dir(data *HardData, item *ItemsNode) { @@ -123,9 +121,7 @@ func i_set_fold(data *HardData, curr, start, end *ItemsNode) { } folds[curr.Dirs] = &tmp - for ptr := data.litems.head; ptr != nil && ptr.next != nil; ptr = ptr.next { - ptr.next.ID = ptr.ID + 1 - } + data.litems.reset_id() } func i_fold_dir(data *HardData, item *ItemsNode) { @@ -200,9 +196,7 @@ func i_delete_dir(data *HardData) { data.litems.last = curr.prev data.litems.curr = curr.prev } - for ptr := data.litems.head; ptr != nil && ptr.next != nil; ptr = ptr.next { - ptr.next.ID = ptr.ID + 1 - } + data.litems.reset_id() if err := os.RemoveAll(dir_path); err != nil { data.ui.s.Fini() c_die("can't remove " + dir_path, err) -- cgit v1.2.3