Commits

ttouch  committed 21a5cf5

Fixed unchained undo while multiplying commands

  • Participants
  • Parent commits fd83607

Comments (0)

Files changed (3)

 - FINDBW prompt? is it needed?
 - Support multiple marks (with S_Parameter)
 - Instead of delete, just cut
+- Add folding support
 
 At config.def.h:
-- Bindings!
 - Use local/system script path and all
 - Choose color-set for either black or white bg
 - Define more syntaxes
 { .keyv.c = { '^' },      { 0,     0,    0,   0 },  f_move,      { .m = m_bol          } },
 { .keyv.c = { 'A' },      { 0,     0,    0,   0 },  f_move,      { .m = m_eol          } },
 { .keyv.c = { 'A' },      { 0,     0,    0,   0 },  f_toggle,    { .i = S_Command      } },
+{ .keyv.c = { 'a' },      { t_eol, 0,    0,   0 },  f_toggle,    { .i = S_Command      } },
 { .keyv.c = { 'a' },      { 0,     0,    0,   0 },  f_move,      { .m = m_nextchar     } },
 { .keyv.c = { 'a' },      { 0,     0,    0,   0 },  f_toggle,    { .i = S_Command      } },
 { .keyv.c = { 'b' },      { t_sent,0,    0,   0 },  f_adjective, { .m = m_prevword     } },
 	Filepos newcur;
 
 	newcur=i_addtext((char*)arg->v, fcur);
+
 	if((statusflags & S_GroupUndo) && undos && (undos->flags & UndoIns) && fcur.o == undos->endo && undos->endl == i_lineno(fcur.l) && ((char*)arg->v)[0] != '\n')
 		i_addtoundo(newcur, arg->v);
 	else {
 		i_addundo(TRUE, fcur, newcur, strdup((char*)arg->v));
 		if(fcur.l!=newcur.l) fsel=newcur;
 	}
+
 	fcur=fsel=newcur;
 	statusflags|=(S_Modified|S_GroupUndo);
 	lastaction=LastInsert;
 	u=(isredo?redos:undos);
 	fsel.o=u->starto, fsel.l=i_lineat(u->startl);
 	fcur=fsel;
+
 	while(u) {
 		start.o=u->starto, start.l=i_lineat(u->startl);
 		end.o=u->endo,     end.l=i_lineat(u->endl);
+
 		if(isredo ^ (u->flags & UndoIns)) {
 			i_sortpos(&start, &end);
 			i_deltext(start, end);
 			fcur=fsel=start;
 		} else
 			fcur=fsel=i_addtext(u->str, fcur);
+
 		if(isredo)
 			redos=u->prev, u->prev=undos, undos=u;
 		else
 			undos=u->prev, u->prev=redos, redos=u;
+
 		if (!(u->flags & (isredo?RedoMore:UndoMore))) break;
 		u=(isredo?redos:undos);
 	}
 	oldsiz=strlen(undos->str), newsiz=strlen(s);
 	undos->endl=i_lineno(newend.l);
 	undos->endo=newend.o;
+
 	if((undos->str=(char*)realloc(undos->str, 1+oldsiz+newsiz)) == NULL)
 		i_die("Can't malloc.\n");
+
 	strncat(undos->str, s, newsiz);
 }
 
 i_addundo(bool ins, Filepos start, Filepos end, char *s) {
 	Undo *u;
 
+	if(strlen(s) == 0) return;
+	if(statusflags & S_GroupUndo) {
+		end.l = i_lineat((undos->endl - undos->startl) + i_lineno(end.l));
+		i_addtoundo(end, s);
+		return;
+	}
+
 	if(redos) i_killundos(&redos); /* Once you make a change, the old redos go away */
 	if ((u=(Undo*)calloc(1, sizeof(Undo))) == NULL)
 		i_die("Can't malloc.\n");
+
 	u->flags  = (ins?UndoIns:0);
 	u->startl = i_lineno(start.l);
 	u->endl   = i_lineno(end.l);
 	int i;
 
 	if(statusflags & S_Multiply) {
-		//statusflags|=S_GroupUndo;
-		for(i=0; i<multiply; i++)
+		func(&arg);
+		statusflags|=S_GroupUndo;
+
+		for(i=1; i<multiply; i++)
 			func(&arg);
 
+		statusflags&=~S_GroupUndo;
 		statusflags&=~S_Multiply;
 		multiply=1;
 	} else