Fixed missing undo bug in Fl_Text_Editor. Undo would be performed on

text buffer AND attribute buffer, which in turn confused the undo buffer.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2836 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher
2002-11-12 22:48:36 +00:00
parent 46d894851e
commit 332ae4a831
3 changed files with 52 additions and 32 deletions
+5 -2
View File
@@ -1,5 +1,5 @@
// //
// "$Id: Fl_Text_Buffer.H,v 1.3.2.6 2002/11/05 19:53:50 matthiaswm Exp $" // "$Id: Fl_Text_Buffer.H,v 1.3.2.7 2002/11/12 22:48:36 matthiaswm Exp $"
// //
// Header file for Fl_Text_Buffer class. // Header file for Fl_Text_Buffer class.
// //
@@ -84,6 +84,7 @@ class FL_EXPORT Fl_Text_Buffer {
void replace(int start, int end, const char *text); void replace(int start, int end, const char *text);
void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos); void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
int undo(int *cp=0); int undo(int *cp=0);
void canUndo(char flag=1);
int insertfile(const char *file, int pos, int buflen = 128*1024); int insertfile(const char *file, int pos, int buflen = 128*1024);
int appendfile(const char *file, int buflen = 128*1024) int appendfile(const char *file, int buflen = 128*1024)
{ return insertfile(file, length(), buflen); } { return insertfile(file, length(), buflen); }
@@ -245,10 +246,12 @@ class FL_EXPORT Fl_Text_Buffer {
with something else. This is the else, but with something else. This is the else, but
of course, things get quite messy when you of course, things get quite messy when you
use it */ use it */
char mCanUndo; /* if this buffer is used for attributes, it must
not do any undo calls */
}; };
#endif #endif
// //
// End of "$Id: Fl_Text_Buffer.H,v 1.3.2.6 2002/11/05 19:53:50 matthiaswm Exp $". // End of "$Id: Fl_Text_Buffer.H,v 1.3.2.7 2002/11/12 22:48:36 matthiaswm Exp $".
// //
+44 -28
View File
@@ -1,5 +1,5 @@
// //
// "$Id: Fl_Text_Buffer.cxx,v 1.9.2.14 2002/11/08 15:22:15 easysw Exp $" // "$Id: Fl_Text_Buffer.cxx,v 1.9.2.15 2002/11/12 22:48:36 matthiaswm Exp $"
// //
// Copyright 2001-2002 by Bill Spitzak and others. // Copyright 2001-2002 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under // Original code Copyright Mark Edel. Permission to distribute under
@@ -118,6 +118,7 @@ Fl_Text_Buffer::Fl_Text_Buffer( int requestedSize ) {
mPredeleteCbArgs = NULL; mPredeleteCbArgs = NULL;
mCursorPosHint = 0; mCursorPosHint = 0;
mNullSubsChar = '\0'; mNullSubsChar = '\0';
mCanUndo = 1;
#ifdef PURIFY #ifdef PURIFY
{ int i; for (i = mGapStart; i < mGapEnd; i++) mBuf[ i ] = '.'; } { int i; for (i = mGapStart; i < mGapEnd; i++) mBuf[ i ] = '.'; }
#endif #endif
@@ -337,7 +338,7 @@ void Fl_Text_Buffer::copy( Fl_Text_Buffer *fromBuf, int fromStart,
** from the undo buffer ** from the undo buffer
*/ */
int Fl_Text_Buffer::undo(int *cursorPos) { int Fl_Text_Buffer::undo(int *cursorPos) {
if (undowidget != this || !undocut && !undoinsert) return 0; if (undowidget != this || !undocut && !undoinsert &&!mCanUndo) return 0;
int ilen = undocut; int ilen = undocut;
int xlen = undoinsert; int xlen = undoinsert;
@@ -370,6 +371,13 @@ int Fl_Text_Buffer::undo(int *cursorPos) {
return 1; return 1;
} }
/*
** let the undo system know if we can undo changes
*/
void Fl_Text_Buffer::canUndo(char flag) {
mCanUndo = flag;
}
/* /*
** Insert "text" columnwise into buffer starting at displayed character ** Insert "text" columnwise into buffer starting at displayed character
** position "column" on the line beginning at "startPos". Opens a rectangular ** position "column" on the line beginning at "startPos". Opens a rectangular
@@ -1338,16 +1346,18 @@ int Fl_Text_Buffer::insert_( int pos, const char *s ) {
mLength += insertedLength; mLength += insertedLength;
update_selections( pos, 0, insertedLength ); update_selections( pos, 0, insertedLength );
if ( undowidget==this && undoat==pos && undoinsert ) { if (mCanUndo) {
undoinsert += insertedLength; if ( undowidget==this && undoat==pos && undoinsert ) {
undoinsert += insertedLength;
}
else {
undoinsert = insertedLength;
undoyankcut = (undoat==pos) ? undocut : 0 ;
}
undoat = pos+insertedLength;
undocut = 0;
undowidget = this;
} }
else {
undoinsert = insertedLength;
undoyankcut = (undoat==pos) ? undocut : 0 ;
}
undoat = pos+insertedLength;
undocut = 0;
undowidget = this;
return insertedLength; return insertedLength;
} }
@@ -1360,32 +1370,38 @@ int Fl_Text_Buffer::insert_( int pos, const char *s ) {
void Fl_Text_Buffer::remove_( int start, int end ) { void Fl_Text_Buffer::remove_( int start, int end ) {
/* if the gap is not contiguous to the area to remove, move it there */ /* if the gap is not contiguous to the area to remove, move it there */
if ( undowidget==this && undoat==end && undocut ) { if (mCanUndo) {
undobuffersize( undocut+end-start+1 ); if ( undowidget==this && undoat==end && undocut ) {
memmove( undobuffer+end-start, undobuffer, undocut ); undobuffersize( undocut+end-start+1 );
undocut += end-start; memmove( undobuffer+end-start, undobuffer, undocut );
} undocut += end-start;
else { }
undocut = end-start; else {
undobuffersize(undocut); undocut = end-start;
undobuffersize(undocut);
}
undoat = start;
undoinsert = 0;
undoyankcut = 0;
undowidget = this;
} }
undoat = start;
undoinsert = 0;
undoyankcut = 0;
undowidget = this;
if ( start > mGapStart ) { if ( start > mGapStart ) {
memcpy( undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start ); if (mCanUndo)
memcpy( undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start );
move_gap( start ); move_gap( start );
} }
else if ( end < mGapStart ) { else if ( end < mGapStart ) {
memcpy( undobuffer, mBuf+start, end-start ); if (mCanUndo)
memcpy( undobuffer, mBuf+start, end-start );
move_gap( end ); move_gap( end );
} }
else { else {
int prelen = mGapStart - start; int prelen = mGapStart - start;
memcpy( undobuffer, mBuf+start, prelen ); if (mCanUndo) {
memcpy( undobuffer+prelen, mBuf+mGapEnd, end-start-prelen); memcpy( undobuffer, mBuf+start, prelen );
memcpy( undobuffer+prelen, mBuf+mGapEnd, end-start-prelen);
}
} }
/* expand the gap to encompass the deleted characters */ /* expand the gap to encompass the deleted characters */
@@ -2493,5 +2509,5 @@ Fl_Text_Buffer::outputfile(const char *file, int start, int end, int buflen) {
// //
// End of "$Id: Fl_Text_Buffer.cxx,v 1.9.2.14 2002/11/08 15:22:15 easysw Exp $". // End of "$Id: Fl_Text_Buffer.cxx,v 1.9.2.15 2002/11/12 22:48:36 matthiaswm Exp $".
// //
+3 -2
View File
@@ -1,5 +1,5 @@
// //
// "$Id: Fl_Text_Display.cxx,v 1.12.2.35 2002/10/29 17:34:44 easysw Exp $" // "$Id: Fl_Text_Display.cxx,v 1.12.2.36 2002/11/12 22:48:36 matthiaswm Exp $"
// //
// Copyright 2001-2002 by Bill Spitzak and others. // Copyright 2001-2002 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under // Original code Copyright Mark Edel. Permission to distribute under
@@ -197,6 +197,7 @@ Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer,
mUnfinishedHighlightCB = unfinishedHighlightCB; mUnfinishedHighlightCB = unfinishedHighlightCB;
mHighlightCBArg = cbArg; mHighlightCBArg = cbArg;
mStyleBuffer->canUndo(0);
#if 0 #if 0
// FIXME: this is in nedit code -- is it needed? // FIXME: this is in nedit code -- is it needed?
/* Call TextDSetFont to combine font information from style table and /* Call TextDSetFont to combine font information from style table and
@@ -3028,5 +3029,5 @@ int Fl_Text_Display::handle(int event) {
// //
// End of "$Id: Fl_Text_Display.cxx,v 1.12.2.35 2002/10/29 17:34:44 easysw Exp $". // End of "$Id: Fl_Text_Display.cxx,v 1.12.2.36 2002/11/12 22:48:36 matthiaswm Exp $".
// //