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

Fix delete/close of todoist

Currently, when deleting, we jump 2 positions, since we are calling next.
However, the next item becomes the current selected position, so handle better
Properly set selected in some edge cases where we may go from a list to 0
This commit is contained in:
Sean Smith 2019-08-31 19:02:56 -04:00
parent c3a54de181
commit f2c10902b3
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 // Close closes the currently-selected task in the currently-selected project
func (w *Widget) Close() { func (w *Widget) Close() {
w.CurrentProject().closeSelectedTask() w.CurrentProject().closeSelectedTask()
w.SetItemCount(len(w.CurrentProject().tasks))
if w.CurrentProject().isLast() { if w.CurrentProject().isLast() {
w.Prev() w.Prev()
return return
} }
w.CurrentProject().index = w.Selected
w.Next() w.RenderFunction()
} }
// Delete deletes the currently-selected task in the currently-selected project // Delete deletes the currently-selected task in the currently-selected project
func (w *Widget) Delete() { func (w *Widget) Delete() {
w.CurrentProject().deleteSelectedTask() w.CurrentProject().deleteSelectedTask()
w.SetItemCount(len(w.CurrentProject().tasks))
if w.CurrentProject().isLast() { if w.CurrentProject().isLast() {
w.Prev() w.Prev()
return
} }
w.CurrentProject().index = w.Selected
w.Next() w.RenderFunction()
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

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