*** /mit/ktools/src/owl/src/functions.c	Thu Jun  6 10:38:07 2002
--- functions.c	Mon Jun 10 00:20:49 2002
***************
*** 634,639 ****
--- 634,641 ----
        }
        if (j==curmsg) {
  	j--;
+       } else if (j < curmsg) {
+         j = curmsg-1;
        }
        owl_global_set_topmsg(&g, j+1);
        return;
***************
*** 1398,1405 ****
--- 1400,1409 ----
  
  
  void owl_function_change_view(char *filtname) {
+   int curid, i;
    owl_view *v;
    owl_filter *f;
+   owl_message *m;
  
    v=owl_global_get_current_view(&g);
    f=owl_global_get_filter(&g, filtname);
***************
*** 1408,1417 ****
      return;
    }
  
    owl_view_free(v);
    owl_view_create(v, f);
  
!   owl_global_set_curmsg(&g, 0);
    owl_global_set_curmsg_vert_offset(&g, 0);
    owl_global_set_direction_downwards(&g);
    owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
--- 1412,1436 ----
      return;
    }
  
+   m = owl_view_get_element(v, owl_global_get_curmsg(&g));
+ 
    owl_view_free(v);
    owl_view_create(v, f);
  
!   /* figure out the message with the closest id in the new view
!      there will be no message if the current view is empty */
!   if (m) {
!     curid = owl_message_get_id(m);
!     for (i=0; i<owl_view_get_size(v)-1; i++) {
!       if (owl_message_get_id(owl_view_get_element(v, i)) >= curid) {
!         break;
!       }
!     }
!   } else {
!     i=0;
!   }
! 
!   owl_global_set_curmsg(&g, i);
    owl_global_set_curmsg_vert_offset(&g, 0);
    owl_global_set_direction_downwards(&g);
    owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
