[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Search and Replace



This patch fixes the infinite replace problem.  I also noticed that
replace just one word instead of globally is broken.  This fixes that
too.

Dennis Payne
dulsi@identicalsoftware.com

--- we_block.c.orig	Fri Sep 17 23:40:14 1999
+++ we_block.c	Thu Sep 16 22:10:52 1999
@@ -1064,9 +1064,9 @@
 
 /* The menu and menuhandling have been rewritten to support only 4 choices
   rather than 3 sets of 2 alternatives.
-    1 Global replace (forward from start of text)
-    2 Forward from Cursor
-    3 Back from Cursor
+    1 Forward from Cursor
+    2 Back from Cursor
+    3 Global replace (forward from start of text)
     4 Selected Text (from start of selection, and only shown if a block _is_
       marked)
   The result window is either 'String NOT Found' or the number of
@@ -1107,11 +1107,11 @@
  e_add_sswstr(5, 8, 0, AltW, fd->sw & 64 ? 1 : 0, "Whole words only  ", o);
  e_add_sswstr(5, 9, 0, AltR, fd->sw & 32 ? 1 : 0, "Regular expression", o);
  e_add_sswstr(5, 10, 0, AltP, 1, "Prompt on Replace ", o);
- e_add_pswstr(0, 33, 7, 0, AltG, 0, "Global Replace     ", o);
- e_add_pswstr(0, 33, 8, 0, AltF, fd->sw & 2 ? 1 : 0, "Forward from Cursor", o);
- e_add_pswstr(0, 33, 9, 0, AltB, fd->sw & 2 ? 1 : 0, "Back from Cursor   ", o);
+ e_add_pswstr(0, 33, 7, 0, AltF, 0, "Forward from Cursor", o);
+ e_add_pswstr(0, 33, 8, 0, AltB, fd->sw & 4 ? 1 : 0, "Back from Cursor   ", o);
+ e_add_pswstr(0, 33, 9, 0, AltG, fd->sw & 2 ? 1 : 0, "Global Replace     ", o);
  if (s->mark_end.y)
-  e_add_pswstr(0, 33, 10, 0, AltS, fd->sw & 2 ? 1 : 0, "Selected Text      ", o);
+  e_add_pswstr(0, 33, 10, 0, AltS, fd->sw & 10 ? 1 : 0, "Selected Text      ", o);
  e_add_bttstr(10, 12, 1, AltO, " Ok ", NULL, o);
  e_add_bttstr(41, 12, -1, WPE_ESC, "Cancel", NULL, o);
  e_add_bttstr(22, 12, 7, AltA, "Change All", NULL, o);
@@ -1126,25 +1126,27 @@
     + (o->sstr[2]->num << 5) + (o->sstr[3]->num << 4);
   switch (o->pstr[0]->num)
   {
-   case 0:
+   case 2:
     fd->sw |= 2;
     b->b.x = b->b.y = 0;
     break;
-   case 2:
+   case 1:
     fd->sw |= 4;
     b->b.x = b->bf[b->mxlines-1].len;
     b->b.y = b->mxlines-1;
     break;
    case 3:
-    fd->sw|=10;
-    b->b.x=s->mark_begin.x;
-    b->b.y=s->mark_begin.y;
+    fd->sw |= 10;
+    b->b.x = s->mark_begin.x;
+    b->b.y = s->mark_begin.y;
+   default:
+    break;
   }
  }
  freeostr(o);
  if (ret != WPE_ESC)
  {
-  while (e_rep_search(f) && ret == AltA)
+  while (e_rep_search(f) && ((ret == AltA) || (!found)))
   {
    found++;
    if (f->a.y < 11)
@@ -1169,7 +1171,7 @@
     e_del_nchar(b, s, s->fa.x, b->b.y, fd->sn);
     e_ins_nchar(b, s, (unsigned char *)fd->replace, s->fa.x, b->b.y, fd->rn);
     e_undo_sw = 0;
-    s->fe.x = s->fa.x + fd->rn - fd->sn;
+    s->fe.x = s->fa.x + fd->rn;
     b->b.x = !(fd->sw & 4) ? s->fe.x : s->fa.x;
     e_schirm(f, 1);
    }