Index: em-folder-view.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-folder-view.c,v
retrieving revision 1.159
diff -u -p -r1.159 em-folder-view.c
--- em-folder-view.c	28 Aug 2006 15:09:43 -0000	1.159
+++ em-folder-view.c	31 Aug 2006 22:53:33 -0000
@@ -951,16 +951,25 @@ emfv_popup_delete(EPopup *ep, EPopupItem
 {
 	EMFolderView *emfv = data;
 	int count;
-	
+	gboolean is_root = FALSE;
+
+	if (emfv->list->threaded && emfv->hide_deleted) {
+		ETreePath node;
+		
+		node = g_hash_table_lookup(emfv->list->uid_nodemap, emfv->list->cursor_uid);
+		if (e_tree_model_node_depth(emfv->list->model, node)  == 1)
+			is_root=TRUE;
+	}
+
 	count = em_folder_view_mark_selected(emfv, CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED);
 	
 	if (count == 1) {
 		if (!emfv->list->threaded && !message_list_select (emfv->list, MESSAGE_LIST_SELECT_NEXT, 0, 0) && emfv->hide_deleted)
 			message_list_select (emfv->list, MESSAGE_LIST_SELECT_PREVIOUS, 0, 0);
 		else if (emfv->list->threaded) {
-			if (emfv->hide_deleted)
-				message_list_select_uid (emfv->list, "");
-			else 
+			if (is_root)
+					message_list_select (emfv->list, MESSAGE_LIST_SELECT_PREVIOUS, 0, 0);
+			else
 				message_list_select (emfv->list, MESSAGE_LIST_SELECT_NEXT, 0, 0);
 		}
 	}
