1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge pull request #588 from Seanstoppable/fixscrollableandtodoist

Fix delete/close of todoist
This commit is contained in:
Chris Cummer 2019-09-01 08:20:58 -07:00 committed by GitHub
commit 46a4c82e1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -104,25 +104,26 @@ func (widget *Widget) Unselect() {
// Close closes the currently-selected task in the currently-selected project
func (w *Widget) Close() {
w.CurrentProject().closeSelectedTask()
w.SetItemCount(len(w.CurrentProject().tasks))
if w.CurrentProject().isLast() {
w.Prev()
return
}
w.Next()
w.CurrentProject().index = w.Selected
w.RenderFunction()
}
// Delete deletes the currently-selected task in the currently-selected project
func (w *Widget) Delete() {
w.CurrentProject().deleteSelectedTask()
w.SetItemCount(len(w.CurrentProject().tasks))
if w.CurrentProject().isLast() {
w.Prev()
return
}
w.Next()
w.CurrentProject().index = w.Selected
w.RenderFunction()
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -35,6 +35,9 @@ func (widget *ScrollableWidget) SetRenderFunction(displayFunc func()) {
func (widget *ScrollableWidget) SetItemCount(items int) {
widget.maxItems = items
if items == 0 {
widget.Selected = -1
}
}
func (widget *ScrollableWidget) GetSelected() int {
@ -54,6 +57,9 @@ func (widget *ScrollableWidget) Next() {
if widget.Selected >= widget.maxItems {
widget.Selected = 0
}
if widget.maxItems == 0 {
widget.Selected = -1
}
widget.RenderFunction()
}
@ -62,6 +68,9 @@ func (widget *ScrollableWidget) Prev() {
if widget.Selected < 0 {
widget.Selected = widget.maxItems - 1
}
if widget.maxItems == 0 {
widget.Selected = -1
}
widget.RenderFunction()
}