From 977eb55944019f48fcc861babc0aa63d3427352a Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Wed, 30 May 2018 21:42:26 +0430 Subject: [PATCH 1/2] todo: update index of selected item in the end --- todo/display.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/todo/display.go b/todo/display.go index 607173cc..29653fa8 100644 --- a/todo/display.go +++ b/todo/display.go @@ -34,8 +34,6 @@ func (widget *Widget) display() { uncheckedLen++ if widget.View.HasFocus() && item == selected { - // set selected item index - newList.selected = idx foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") } @@ -52,11 +50,10 @@ func (widget *Widget) display() { newList.Items = append(newList.Items, item) } - for idx, item := range checked { + for _, item := range checked { foreColor, backColor := Config.UString("wtf.mods.todo.colors.checked", "white"), "black" if widget.View.HasFocus() && item == selected { - newList.selected = idx + uncheckedLen foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") } @@ -73,6 +70,13 @@ func (widget *Widget) display() { newList.Items = append(newList.Items, item) } + // update new index of selected item + for idx, item := range newList.Items { + if item == selected { + newList.selected = idx + } + } + // update list with new Items and selected item index widget.list = &newList From 3c66bc9152461e7bf0e7b8d6c53cfa7e325d66ac Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Wed, 30 May 2018 21:50:27 +0430 Subject: [PATCH 2/2] removed unused variable --- todo/display.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/todo/display.go b/todo/display.go index 29653fa8..971e2d3a 100644 --- a/todo/display.go +++ b/todo/display.go @@ -15,15 +15,14 @@ func (widget *Widget) display() { str := "" checked := []*Item{} - uncheckedLen := 0 - var selected *Item + var selectedItem *Item var newList List for idx, item := range widget.list.Items { foreColor, backColor := "white", "black" // save the selected one if idx == widget.list.selected { - selected = item + selectedItem = item } if item.Checked { @@ -31,9 +30,7 @@ func (widget *Widget) display() { continue } - uncheckedLen++ - - if widget.View.HasFocus() && item == selected { + if widget.View.HasFocus() && item == selectedItem { foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") } @@ -53,7 +50,7 @@ func (widget *Widget) display() { for _, item := range checked { foreColor, backColor := Config.UString("wtf.mods.todo.colors.checked", "white"), "black" - if widget.View.HasFocus() && item == selected { + if widget.View.HasFocus() && item == selectedItem { foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") } @@ -70,9 +67,9 @@ func (widget *Widget) display() { newList.Items = append(newList.Items, item) } - // update new index of selected item + // update selected index with new index of selected item for idx, item := range newList.Items { - if item == selected { + if item == selectedItem { newList.selected = idx } }