--- tsin.c	2008-01-13 02:16:09.000000000 +0800
+++ tsin-cwlin.c	2008-01-13 02:11:23.000000000 +0800
@@ -37,6 +37,8 @@
 static gboolean full_match;
 static gboolean tsin_half_full;
 
+int bufferEditing = 0; //0 = buffer editing mode is disabled
+
 typedef struct {
   phokey_t phokey[MAX_PHRASE_LEN];
   int phidx;
@@ -1560,14 +1562,108 @@
            if (gcin_pop_up_win)
              hide_win0();
            return 1;
-         } else
-         if (xkey>=XK_1 && xkey<=XK_3) {
+         } else if (xkey == XK_e) {
+	   //trigger
+	   if (!bufferEditing) {
+	     bufferEditing = 1;
+           }
+           else {
+	     bufferEditing = 0;
+           }
+	   return 1;
+         } else if (xkey>=XK_1 && xkey<=XK_3) {
            return 1;
          } else {
            return 0;
          }
        }
 
+       if (bufferEditing) {
+         if (xkey==XK_h) {
+	   close_selection_win();
+	   if (c_idx) {
+	     clrcursor();
+	     c_idx--;
+	     drawcursor();
+	     return 1;
+	   }
+	   if (c_len)
+	     return 1;
+           return 0;
+         }
+	 else if (xkey==XK_l) {
+	   close_selection_win();
+	   if (c_idx < c_len) {
+	     clrcursor();
+	     c_idx++;
+	     drawcursor();
+	     return 1;
+	   }
+	   if (c_len)
+	     return 1;
+	   return 0;
+	 }
+	 else if (xkey==XK_x) {
+          if (c_idx == c_len)
+            return 0;
+  
+          close_selection_win();
+          clear_disp_ph_sta();
+          ityp3_pho=0;
+          pre_selN = 0;
+  
+          for(j=3;j>=0;j--)
+            if (typ_pho[j]) {
+              typ_pho[j]=0;
+              disp_in_area_pho_tsin();
+              return 1;
+            }
+  
+          clrcursor();
+          pst=k=chpho[c_idx].psta;
+  
+          for(k=c_idx;k<c_len;k++) {
+            chpho[k] = chpho[k+1];
+            chpho[k].psta=chpho[k+1].psta-1;
+          }
+  
+          c_len--;
+          hide_char(c_len);
+          init_chpho_i(c_len);
+  
+          prbuf();
+  
+          compact_win0_x();
+  
+          if (!c_idx) {
+            clear_match();
+          }
+          else {
+            k=c_idx-1;
+            pst=chpho[k].psta;
+  
+            while (k>0 && chpho[k].psta==pst)
+              k--;
+  
+            if (chpho[k].psta!=pst)
+              k++;
+  
+            match_len= c_idx - k;
+            if (!(match_len=scanphr(k, match_len, FALSE)))
+              ph_sta=-1;
+            else
+              ph_sta=k;
+              pre_selN = 0;
+          }
+  
+          if (!c_len && gcin_pop_up_win)
+            hide_win0();
+  
+          disp_ph_sta();
+          return 1;
+	 }
+       }
+
        char *pp;
 
        char xkey_lcase = xkey;
