changeset 189:4f3975f1b852

[/trunk] Changeset 201 by mikael * Add hbuf_previous_persistent(). Now we should not jump to the buffer's bottom when increasing the screen width.
author mikael
date Fri, 06 May 2005 14:34:51 +0000
parents 7604e3cdbb86
children 9c2023d60986
files mcabber/src/TODO mcabber/src/hbuf.c mcabber/src/hbuf.h mcabber/src/screen.c
diffstat 4 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/TODO	Fri May 06 09:58:44 2005 +0000
+++ b/mcabber/src/TODO	Fri May 06 14:34:51 2005 +0000
@@ -13,10 +13,9 @@
 * Key bindings (ex: F5 <-> /group toggle)
 * Pending message not displayed if buddy outside Contact window,
   maybe we could show it someway (maybe just a flag?).
-* Add a function in hbuf ~previous_persistent(hbuf *top) (to avoid loosing the
-  top variable on a resize).
 * Show number of online contacts in folded groups
 * Buddy buffer in full width (handy for cut'n paste!)
+* Emacs key bindings in input line (ctrl-w, ctrl-t)
 
 * Commands! :-)
   - /roster <hide_offline|show_offline|top|bottom>
--- a/mcabber/src/hbuf.c	Fri May 06 09:58:44 2005 +0000
+++ b/mcabber/src/hbuf.c	Fri May 06 14:34:51 2005 +0000
@@ -217,6 +217,26 @@
   }
 }
 
+//  hbuf_previous_persistent()
+// Returns the previous persistent block (line).  If the given line is
+// persistent, then it is returned.
+// This function is used for example when resizing a buffer.  If the top of the
+// screen is on a non-persistent block, then a screen resize could destroy this
+// line...
+GList *hbuf_previous_persistent(GList *l_line)
+{
+  hbuf_block *hbuf_b_elt;
+
+  while (l_line) {
+    hbuf_b_elt = (hbuf_block*)l_line->data;
+    if (hbuf_b_elt->flags & HBB_FLAG_PERSISTENT)
+      return l_line;
+    l_line = g_list_previous(l_line);
+  }
+
+  return NULL;
+}
+
 //  hbuf_get_lines(hbuf, n, where)  FIXME bad comments XXX
 // Returns an array of 2*n pointers (for n prefixes + n lines from hbuf)
 // (prefix line 1, line 1, prefix line 2, line 2, etc.)
--- a/mcabber/src/hbuf.h	Fri May 06 09:58:44 2005 +0000
+++ b/mcabber/src/hbuf.h	Fri May 06 14:34:51 2005 +0000
@@ -30,6 +30,7 @@
         guint prefix_flags, guint width);
 void hbuf_free(GList **p_hbuf);
 void hbuf_rebuild(GList **p_hbuf, unsigned int width);
+GList *hbuf_previous_persistent(GList *l_line);
 
 hbb_line **hbuf_get_lines(GList *hbuf, unsigned int n);
 
--- a/mcabber/src/screen.c	Fri May 06 09:58:44 2005 +0000
+++ b/mcabber/src/screen.c	Fri May 06 14:34:51 2005 +0000
@@ -533,6 +533,7 @@
   list_for_each_safe(pos, n, &window_list) {
     search_entry = window_entry(pos);
     if (search_entry->win) {
+      GList *rescue_top;
       // Resize buddy window (no need to move it)
       wresize(search_entry->win, lines, cols);
       werase(search_entry->win);
@@ -541,8 +542,11 @@
         replace_panel(search_entry->panel, search_entry->win);
       }
       // Redo line wrapping
+      rescue_top = hbuf_previous_persistent(search_entry->top);
       hbuf_rebuild(&search_entry->hbuf,
               maxX - ROSTER_WIDTH - PREFIX_WIDTH);
+      if (g_list_position(g_list_first(search_entry->hbuf), search_entry->top) == -1)
+        search_entry->top = rescue_top;
     }
   }