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:
parent
46d894851e
commit
332ae4a831
@ -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.
|
||||
//
|
||||
@ -84,6 +84,7 @@ class FL_EXPORT Fl_Text_Buffer {
|
||||
void replace(int start, int end, const char *text);
|
||||
void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
|
||||
int undo(int *cp=0);
|
||||
void canUndo(char flag=1);
|
||||
int insertfile(const char *file, int pos, int buflen = 128*1024);
|
||||
int appendfile(const char *file, int buflen = 128*1024)
|
||||
{ return insertfile(file, length(), buflen); }
|
||||
@ -245,10 +246,12 @@ class FL_EXPORT Fl_Text_Buffer {
|
||||
with something else. This is the else, but
|
||||
of course, things get quite messy when you
|
||||
use it */
|
||||
char mCanUndo; /* if this buffer is used for attributes, it must
|
||||
not do any undo calls */
|
||||
};
|
||||
|
||||
#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 $".
|
||||
//
|
||||
|
||||
@ -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.
|
||||
// Original code Copyright Mark Edel. Permission to distribute under
|
||||
@ -118,6 +118,7 @@ Fl_Text_Buffer::Fl_Text_Buffer( int requestedSize ) {
|
||||
mPredeleteCbArgs = NULL;
|
||||
mCursorPosHint = 0;
|
||||
mNullSubsChar = '\0';
|
||||
mCanUndo = 1;
|
||||
#ifdef PURIFY
|
||||
{ int i; for (i = mGapStart; i < mGapEnd; i++) mBuf[ i ] = '.'; }
|
||||
#endif
|
||||
@ -337,7 +338,7 @@ void Fl_Text_Buffer::copy( Fl_Text_Buffer *fromBuf, int fromStart,
|
||||
** from the undo buffer
|
||||
*/
|
||||
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 xlen = undoinsert;
|
||||
@ -370,6 +371,13 @@ int Fl_Text_Buffer::undo(int *cursorPos) {
|
||||
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
|
||||
** 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;
|
||||
update_selections( pos, 0, insertedLength );
|
||||
|
||||
if ( undowidget==this && undoat==pos && undoinsert ) {
|
||||
undoinsert += insertedLength;
|
||||
if (mCanUndo) {
|
||||
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;
|
||||
}
|
||||
@ -1360,32 +1370,38 @@ int Fl_Text_Buffer::insert_( int pos, const char *s ) {
|
||||
void Fl_Text_Buffer::remove_( int start, int end ) {
|
||||
/* if the gap is not contiguous to the area to remove, move it there */
|
||||
|
||||
if ( undowidget==this && undoat==end && undocut ) {
|
||||
undobuffersize( undocut+end-start+1 );
|
||||
memmove( undobuffer+end-start, undobuffer, undocut );
|
||||
undocut += end-start;
|
||||
}
|
||||
else {
|
||||
undocut = end-start;
|
||||
undobuffersize(undocut);
|
||||
if (mCanUndo) {
|
||||
if ( undowidget==this && undoat==end && undocut ) {
|
||||
undobuffersize( undocut+end-start+1 );
|
||||
memmove( undobuffer+end-start, undobuffer, undocut );
|
||||
undocut += end-start;
|
||||
}
|
||||
else {
|
||||
undocut = end-start;
|
||||
undobuffersize(undocut);
|
||||
}
|
||||
undoat = start;
|
||||
undoinsert = 0;
|
||||
undoyankcut = 0;
|
||||
undowidget = this;
|
||||
}
|
||||
undoat = start;
|
||||
undoinsert = 0;
|
||||
undoyankcut = 0;
|
||||
undowidget = this;
|
||||
|
||||
if ( start > mGapStart ) {
|
||||
memcpy( undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start );
|
||||
if (mCanUndo)
|
||||
memcpy( undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start );
|
||||
move_gap( start );
|
||||
}
|
||||
else if ( end < mGapStart ) {
|
||||
memcpy( undobuffer, mBuf+start, end-start );
|
||||
if (mCanUndo)
|
||||
memcpy( undobuffer, mBuf+start, end-start );
|
||||
move_gap( end );
|
||||
}
|
||||
else {
|
||||
int prelen = mGapStart - start;
|
||||
memcpy( undobuffer, mBuf+start, prelen );
|
||||
memcpy( undobuffer+prelen, mBuf+mGapEnd, end-start-prelen);
|
||||
if (mCanUndo) {
|
||||
memcpy( undobuffer, mBuf+start, prelen );
|
||||
memcpy( undobuffer+prelen, mBuf+mGapEnd, end-start-prelen);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 $".
|
||||
//
|
||||
|
||||
@ -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.
|
||||
// Original code Copyright Mark Edel. Permission to distribute under
|
||||
@ -197,6 +197,7 @@ Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer,
|
||||
mUnfinishedHighlightCB = unfinishedHighlightCB;
|
||||
mHighlightCBArg = cbArg;
|
||||
|
||||
mStyleBuffer->canUndo(0);
|
||||
#if 0
|
||||
// FIXME: this is in nedit code -- is it needed?
|
||||
/* 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 $".
|
||||
//
|
||||
|
||||
Loading…
Reference in New Issue
Block a user