diff --git a/checklist/checklist.go b/checklist/checklist.go index 7e293878..d65e1d9f 100644 --- a/checklist/checklist.go +++ b/checklist/checklist.go @@ -53,21 +53,6 @@ func (list *Checklist) Delete() { list.Prev() } -// Demote moves the selected item down in the checklist -func (list *Checklist) Demote() { - if list.IsUnselectable() { - return - } - - j := list.selected + 1 - if j >= len(list.Items) { - j = 0 - } - - list.Swap(list.selected, j) - list.selected = j -} - // IsSelectable returns true if the checklist has selectable items, false if it does not func (list *Checklist) IsSelectable() bool { return list.selected >= 0 && list.selected < len(list.Items) @@ -78,14 +63,6 @@ func (list *Checklist) IsUnselectable() bool { return !list.IsSelectable() } -// Next selects the next item in the checklist -func (list *Checklist) Next() { - list.selected = list.selected + 1 - if list.selected >= len(list.Items) { - list.selected = 0 - } -} - // LongestLine returns the length of the longest checklist item's text func (list *Checklist) LongestLine() int { maxLen := 0 @@ -99,29 +76,6 @@ func (list *Checklist) LongestLine() int { return maxLen } -// Prev selects the previous item in the checklist -func (list *Checklist) Prev() { - list.selected = list.selected - 1 - if list.selected < 0 { - list.selected = len(list.Items) - 1 - } -} - -// Promote moves the selected item up in the checklist -func (list *Checklist) Promote() { - if list.IsUnselectable() { - return - } - - j := list.selected - 1 - if j < 0 { - j = len(list.Items) - 1 - } - - list.Swap(list.selected, j) - list.selected = j -} - func (list *Checklist) Selected() int { return list.selected } @@ -182,6 +136,54 @@ func (list *Checklist) Update(text string) { item.Text = text } +/* -------------------- Item Movement -------------------- */ + +// Prev selects the previous item UP in the checklist +func (list *Checklist) Prev() { + list.selected = list.selected - 1 + if list.selected < 0 { + list.selected = len(list.Items) - 1 + } +} + +// Next selects the next item DOWN in the checklist +func (list *Checklist) Next() { + list.selected = list.selected + 1 + if list.selected >= len(list.Items) { + list.selected = 0 + } +} + +// Promote moves the selected item UP in the checklist +func (list *Checklist) Promote() { + if list.IsUnselectable() { + return + } + + k := list.selected - 1 + if k < 0 { + k = len(list.Items) - 1 + } + + list.Swap(list.selected, k) + list.selected = k +} + +// Demote moves the selected item DOWN in the checklist +func (list *Checklist) Demote() { + if list.IsUnselectable() { + return + } + + j := list.selected + 1 + if j >= len(list.Items) { + j = 0 + } + + list.Swap(list.selected, j) + list.selected = j +} + /* -------------------- Sort Interface -------------------- */ func (list *Checklist) Len() int { diff --git a/modules/git/widget.go b/modules/git/widget.go index 68f66fa4..52d067b4 100644 --- a/modules/git/widget.go +++ b/modules/git/widget.go @@ -216,25 +216,3 @@ func (widget *Widget) findGitRepositories(repositories []*GitRepo, directory str return repositories } - -func (widget *Widget) Next() { - widget.Idx = widget.Idx + 1 - if widget.Idx == len(widget.GitRepos) { - widget.Idx = 0 - } - - if widget.DisplayFunction != nil { - widget.DisplayFunction() - } -} - -func (widget *Widget) Prev() { - widget.Idx = widget.Idx - 1 - if widget.Idx < 0 { - widget.Idx = len(widget.GitRepos) - 1 - } - - if widget.DisplayFunction != nil { - widget.DisplayFunction() - } -}