diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index 3b3bfc5f..5d0f5dff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -1216,17 +1216,21 @@ class MainActivity : SimpleActivity() { private fun doDeleteNote(note: Note, deleteFile: Boolean) { ensureBackgroundThread { + val currentNodeIndex = mNotes.indexOf(note) + val noteToRefresh = mNotes[if (currentNodeIndex > 0) currentNodeIndex - 1 else currentNodeIndex + 1] + notesDB.deleteNote(note) widgetsDB.deleteNoteWidgets(note.id!!) - refreshNotes(note, deleteFile) + + refreshNotes(noteToRefresh, deleteFile) } } private fun refreshNotes(note: Note, deleteFile: Boolean) { NotesHelper(this).getNotes { mNotes = it - val firstNoteId = mNotes[0].id - updateSelectedNote(firstNoteId!!) + val noteId = note.id + updateSelectedNote(noteId!!) if (config.widgetNoteId == note.id) { config.widgetNoteId = mCurrentNote.id!! updateWidgets()