Skip to content

Commit

Permalink
fix newItems from being shuffled on insert
Browse files Browse the repository at this point in the history
  • Loading branch information
NiloCK committed Aug 31, 2022
1 parent e91d118 commit 84283ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func getFiles(wd string, extensions []string) []string {
}

func sortItems(items []*tuido.Item) {
sort.Slice(items, func(i, j int) bool {
sort.SliceStable(items, func(i, j int) bool {
if items[i].Importance() > items[j].Importance() {
return true
}
Expand Down
9 changes: 6 additions & 3 deletions tui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ func (t *tui) tryCreateNewItem() {

func (t *tui) createNewItem() {
newItem := tuido.New(t.config.writeto, -1, "")
t.items = append([]*tuido.Item{&newItem}, t.items...)
t.populateRenderSelection()
t.setSelection(0)
t.items = append(t.items, &newItem)
// write directly to renderselection instead of repopulating,
// to avoid a sorting move before setSelection is called.
t.renderSelection = append(t.renderSelection, &newItem)

t.setSelection(len(t.renderSelection) - 1)
t.setEditMode()
}

0 comments on commit 84283ff

Please sign in to comment.