mirror of
https://github.com/fltk/fltk.git
synced 2026-06-05 16:12:13 +08:00
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:
+5
-2
@@ -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 $".
|
||||||
//
|
//
|
||||||
|
|||||||
+19
-3
@@ -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,6 +1346,7 @@ 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 (mCanUndo) {
|
||||||
if ( undowidget==this && undoat==pos && undoinsert ) {
|
if ( undowidget==this && undoat==pos && undoinsert ) {
|
||||||
undoinsert += insertedLength;
|
undoinsert += insertedLength;
|
||||||
}
|
}
|
||||||
@@ -1348,6 +1357,7 @@ int Fl_Text_Buffer::insert_( int pos, const char *s ) {
|
|||||||
undoat = pos+insertedLength;
|
undoat = pos+insertedLength;
|
||||||
undocut = 0;
|
undocut = 0;
|
||||||
undowidget = this;
|
undowidget = this;
|
||||||
|
}
|
||||||
|
|
||||||
return insertedLength;
|
return insertedLength;
|
||||||
}
|
}
|
||||||
@@ -1360,6 +1370,7 @@ 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 (mCanUndo) {
|
||||||
if ( undowidget==this && undoat==end && undocut ) {
|
if ( undowidget==this && undoat==end && undocut ) {
|
||||||
undobuffersize( undocut+end-start+1 );
|
undobuffersize( undocut+end-start+1 );
|
||||||
memmove( undobuffer+end-start, undobuffer, undocut );
|
memmove( undobuffer+end-start, undobuffer, undocut );
|
||||||
@@ -1373,20 +1384,25 @@ void Fl_Text_Buffer::remove_( int start, int end ) {
|
|||||||
undoinsert = 0;
|
undoinsert = 0;
|
||||||
undoyankcut = 0;
|
undoyankcut = 0;
|
||||||
undowidget = this;
|
undowidget = this;
|
||||||
|
}
|
||||||
|
|
||||||
if ( start > mGapStart ) {
|
if ( start > mGapStart ) {
|
||||||
|
if (mCanUndo)
|
||||||
memcpy( undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start );
|
memcpy( undobuffer, mBuf+(mGapEnd-mGapStart)+start, end-start );
|
||||||
move_gap( start );
|
move_gap( start );
|
||||||
}
|
}
|
||||||
else if ( end < mGapStart ) {
|
else if ( end < mGapStart ) {
|
||||||
|
if (mCanUndo)
|
||||||
memcpy( undobuffer, mBuf+start, end-start );
|
memcpy( undobuffer, mBuf+start, end-start );
|
||||||
move_gap( end );
|
move_gap( end );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int prelen = mGapStart - start;
|
int prelen = mGapStart - start;
|
||||||
|
if (mCanUndo) {
|
||||||
memcpy( undobuffer, mBuf+start, prelen );
|
memcpy( undobuffer, mBuf+start, prelen );
|
||||||
memcpy( undobuffer+prelen, mBuf+mGapEnd, end-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 */
|
||||||
mGapEnd += end - mGapStart;
|
mGapEnd += end - mGapStart;
|
||||||
@@ -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.
|
// 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 $".
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user