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

todo: update index of selected item in the end

This commit is contained in:
Hossein Mehrabi 2018-05-30 21:42:26 +04:30
parent 385d6d87d9
commit 977eb55944

View File

@ -34,8 +34,6 @@ func (widget *Widget) display() {
uncheckedLen++ uncheckedLen++
if widget.View.HasFocus() && item == selected { if widget.View.HasFocus() && item == selected {
// set selected item index
newList.selected = idx
foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black")
backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white")
} }
@ -52,11 +50,10 @@ func (widget *Widget) display() {
newList.Items = append(newList.Items, item) 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" foreColor, backColor := Config.UString("wtf.mods.todo.colors.checked", "white"), "black"
if widget.View.HasFocus() && item == selected { if widget.View.HasFocus() && item == selected {
newList.selected = idx + uncheckedLen
foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black")
backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white")
} }
@ -73,6 +70,13 @@ func (widget *Widget) display() {
newList.Items = append(newList.Items, item) 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 // update list with new Items and selected item index
widget.list = &newList widget.list = &newList