[792] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r796 - branches/barnowl_unicode/owl

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:09:46 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Wed,  2 Jan 2008 22:51:28 -0500 (EST)

Author: asedeno
Date: 2008-01-02 22:51:28 -0500 (Wed, 02 Jan 2008)
New Revision: 796

Modified:
   branches/barnowl_unicode/owl/editwin.c
Log:
unicode/glib branch
fixing bugs in editwin bufflen calculations.


Modified: branches/barnowl_unicode/owl/editwin.c
===================================================================
--- branches/barnowl_unicode/owl/editwin.c	2008-01-03 02:35:44 UTC (rev 795)
+++ branches/barnowl_unicode/owl/editwin.c	2008-01-03 03:51:28 UTC (rev 796)
@@ -315,6 +315,7 @@
   e->bufflen -= n;
   e->buff[e->bufflen] = '\0';
 }
+
 /* Insert n bytes at cursor.*/
 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/
 {
@@ -370,7 +371,7 @@
   int z, i, ret, len;
   char tmp[6];
   memset(tmp, '\0', 6);
-  
+
   /* \r is \n */
   if (c == '\r') {
     c = '\n';
@@ -384,7 +385,7 @@
 
   g_unichar_to_utf8(c, tmp);
   len = strlen(tmp);
-  
+
   /* make sure there is enough memory for the new text */
   if ((e->bufflen + len) > (e->allocated - 5)) {
     _owl_editwin_addspace(e);
@@ -403,7 +404,9 @@
   }
 
   /* shift all the other characters right */
-  _owl_editwin_insert_bytes(e, len);
+  if (z != e->bufflen) {
+    _owl_editwin_insert_bytes(e, len);
+  }
 
   /* insert the new character */
   for(i = 0; i < len; i++) {
@@ -413,7 +416,7 @@
   /* housekeeping */
   e->bufflen += len;
   e->buff[e->bufflen] = '\0';
-
+  
   /* advance the cursor */
   z += len;
   _owl_editwin_set_xy_by_index(e, z);
@@ -425,12 +428,12 @@
   int z, oldlen, newlen, i;
   char tmp[6];
   memset(tmp, '\0', 6);
-  
+
   /* \r is \n */
   if (c == '\r') {
     c = '\n';
   }
-
+  
   if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
     /* perhaps later this will change some state that allows the string
        to be read */
@@ -443,14 +446,17 @@
   z = _owl_editwin_get_index_from_xy(e);
   {
     char *t = g_utf8_find_next_char(e->buff + z, NULL);
-    oldlen = (t ? (t - (e->buff + z)) : 1);
+    oldlen = (t ? (t - (e->buff + z)) : 0);
   }
 
-  if ((e->bufflen + newlen - oldlen + 1) > (e->allocated - 5)) {
-    _owl_editwin_addspace(e);
+  /* only if we are at the end of the buffer do we create new space here */
+  if (z == e->bufflen) {
+    if ((e->bufflen+newlen) > (e->allocated-5)) {
+      _owl_editwin_addspace(e);
+    }
   }
-
-  if (oldlen > newlen) {
+  /* if not at the end of the buffer, adjust based in char size difference. */ 
+  else if (oldlen > newlen) {
     _owl_editwin_remove_bytes(e, oldlen-newlen);
   }
   else /* oldlen < newlen */ {
@@ -462,8 +468,11 @@
   }
        
   /* housekeeping */
-  e->buff[e->bufflen] = '\0';
-
+  if (z == e->bufflen) {
+    e->bufflen += newlen;
+    e->buff[e->bufflen] = '\0';
+  }
+  
   /* advance the cursor */
   z += newlen;
   _owl_editwin_set_xy_by_index(e, z);


home help back first fref pref prev next nref lref last post