aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2009-04-19 09:38:40 +0000
committernyamatongwe <unknown>2009-04-19 09:38:40 +0000
commitbbf8cac83a0fbba3b68a17d119a559ecd521997a (patch)
tree4dab662fa7dea25f6329508715bbde47f4f1bd31
parente59f78d0a04cf7c9a2b422da634c0b02ef88ee31 (diff)
downloadscintilla-mirror-bbf8cac83a0fbba3b68a17d119a559ecd521997a.tar.gz
Added UNDO_MAY_COALESCE flag to AddUndoAction.
-rw-r--r--doc/ScintillaDoc.html11
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface4
-rw-r--r--src/CellBuffer.cxx39
-rw-r--r--src/CellBuffer.h4
-rw-r--r--src/Document.h2
-rw-r--r--src/Editor.cxx2
7 files changed, 39 insertions, 24 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 28385d192..0bd5dd181 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -901,7 +901,7 @@ struct TextToFind {
<a class="message" href="#SCI_GETUNDOCOLLECTION">SCI_GETUNDOCOLLECTION</a><br />
<a class="message" href="#SCI_BEGINUNDOACTION">SCI_BEGINUNDOACTION</a><br />
<a class="message" href="#SCI_ENDUNDOACTION">SCI_ENDUNDOACTION</a><br />
- <a class="message" href="#SCI_ADDUNDOACTION">SCI_ADDUNDOACTION(int token)</a><br />
+ <a class="message" href="#SCI_ADDUNDOACTION">SCI_ADDUNDOACTION(int token, int flags)</a><br />
</code>
<p><b id="SCI_UNDO">SCI_UNDO</b><br />
@@ -949,7 +949,7 @@ struct TextToFind {
Alternatively, you can use these to mark a set of operations that you do not want to have
combined with the preceding or following operations if they are undone.</p>
- <p><b id="SCI_ADDUNDOACTION">SCI_ADDUNDOACTION(int token)</b><br />
+ <p><b id="SCI_ADDUNDOACTION">SCI_ADDUNDOACTION(int token, int flags)</b><br />
The container can add its own actions into the undo stack by calling
<code>SCI_ADDUNDOACTION</code> and an <code>SCN_MODIFIED</code>
notification will be sent to the container with the
@@ -958,7 +958,7 @@ struct TextToFind {
redo (<code>SC_PERFORMED_REDO</code>) the action. The token argument supplied is
returned in the <code>token</code> field of the notification.</p>
<p>For example, if the container wanted to allow undo and redo of a 'toggle bookmark' command then
- it could call <code>SCI_ADDUNDOACTION(line)</code> each time the command is performed.
+ it could call <code>SCI_ADDUNDOACTION(line, 0)</code> each time the command is performed.
Then when it receives a notification to undo or redo it toggles a bookmark on the line given by
the token field. If there are different types of commands or parameters that need to be stored into the undo
stack then the container should maintain a stack of its own for the document and use the current
@@ -967,6 +967,11 @@ struct TextToFind {
into a single undo transaction unless grouped with <code>SCI_BEGINUNDOACTION</code>
and <code>SCI_ENDUNDOACTION</code>.</p>
+ <p>The flags argument can be <code>UNDO_MAY_COALESCE</code> (1) if the container action may be
+ coalesced along with any insertion and deletion actions into a single compound action, otherwise 0.
+ Coalescing treats coalescible container actions as transparent so will still only group together insertions that
+ look like typing or deletions that look like multiple uses of the Backspace or Delete keys.
+ </p>
<h2 id="SelectionAndInformation">Selection and information</h2>
<p>Scintilla maintains a selection that stretches between two points, the anchor and the
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 8c1232b8a..27b4e3795 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -705,6 +705,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_ANNOTATIONGETVISIBLE 2549
#define SCI_ANNOTATIONSETSTYLEOFFSET 2550
#define SCI_ANNOTATIONGETSTYLEOFFSET 2551
+#define UNDO_MAY_COALESCE 1
#define SCI_ADDUNDOACTION 2560
#define SCI_STARTRECORD 3001
#define SCI_STOPRECORD 3002
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index e51e9274c..87783ccc0 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1902,8 +1902,10 @@ set void AnnotationSetStyleOffset=2550(int style,)
# Get the start of the range of style numbers used for annotations
get int AnnotationGetStyleOffset=2551(,)
+val UNDO_MAY_COALESCE=1
+
# Add a container action to the undo stack
-fun void AddUndoAction=2560(int token,)
+fun void AddUndoAction=2560(int token, int flags)
# Start notifying the container of all key presses and commands.
fun void StartRecord=3001(,)
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx
index 4115803d0..ae0696662 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -154,7 +154,7 @@ void UndoHistory::EnsureUndoRoom() {
}
void UndoHistory::AppendAction(actionType at, int position, char *data, int lengthData,
- bool &startSequence) {
+ bool &startSequence, bool mayCoalesce) {
EnsureUndoRoom();
//Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, lengthData, currentAction);
//Platform::DebugPrintf("^ %d action %d %d\n", actions[currentAction - 1].at,
@@ -166,28 +166,35 @@ void UndoHistory::AppendAction(actionType at, int position, char *data, int leng
if (currentAction >= 1) {
if (0 == undoSequenceDepth) {
// Top level actions may not always be coalesced
- Action &actPrevious = actions[currentAction - 1];
+ int targetAct = -1;
+ const Action *actPrevious = &(actions[currentAction + targetAct]);
+ // Container actions may forward the coalesce state of Scintilla Actions.
+ while ((actPrevious->at == containerAction) && actPrevious->mayCoalesce) {
+ targetAct--;
+ actPrevious = &(actions[currentAction + targetAct]);
+ }
// See if current action can be coalesced into previous action
// Will work if both are inserts or deletes and position is same
- if (at != actPrevious.at) {
- currentAction++;
- } else if (currentAction == savePoint) {
- currentAction++;
- } else if ((at == insertAction) &&
- (position != (actPrevious.position + actPrevious.lenData))) {
- // Insertions must be immediately after to coalesce
+ if (currentAction == savePoint) {
currentAction++;
} else if (!actions[currentAction].mayCoalesce) {
// Not allowed to coalesce if this set
currentAction++;
- } else if (at == containerAction) {
- // Not allowed to coalesce container actions
+ } else if (!mayCoalesce || !actPrevious->mayCoalesce) {
+ currentAction++;
+ } else if (at == containerAction || actions[currentAction].at == containerAction) {
+ ; // A coalescible containerAction
+ } else if ((at != actPrevious->at) && (actPrevious->at != startAction)) {
+ currentAction++;
+ } else if ((at == insertAction) &&
+ (position != (actPrevious->position + actPrevious->lenData))) {
+ // Insertions must be immediately after to coalesce
currentAction++;
} else if (at == removeAction) {
if ((lengthData == 1) || (lengthData == 2)){
- if ((position + lengthData) == actPrevious.position) {
+ if ((position + lengthData) == actPrevious->position) {
; // Backspace -> OK
- } else if (position == actPrevious.position) {
+ } else if (position == actPrevious->position) {
; // Delete -> OK
} else {
// Removals must be at same position to coalesce
@@ -210,7 +217,7 @@ void UndoHistory::AppendAction(actionType at, int position, char *data, int leng
currentAction++;
}
startSequence = oldCurrentAction != currentAction;
- actions[currentAction].Create(at, position, data, lengthData);
+ actions[currentAction].Create(at, position, data, lengthData, mayCoalesce);
currentAction++;
actions[currentAction].Create(startAction);
maxAction = currentAction;
@@ -585,9 +592,9 @@ void CellBuffer::EndUndoAction() {
uh.EndUndoAction();
}
-void CellBuffer::AddUndoAction(int token) {
+void CellBuffer::AddUndoAction(int token, bool mayCoalesce) {
bool startSequence;
- uh.AppendAction(containerAction, token, 0, 0, startSequence);
+ uh.AppendAction(containerAction, token, 0, 0, startSequence, mayCoalesce);
}
void CellBuffer::DeleteUndoHistory() {
diff --git a/src/CellBuffer.h b/src/CellBuffer.h
index 395f75f0e..5af135736 100644
--- a/src/CellBuffer.h
+++ b/src/CellBuffer.h
@@ -101,7 +101,7 @@ public:
UndoHistory();
~UndoHistory();
- void AppendAction(actionType at, int position, char *data, int length, bool &startSequence);
+ void AppendAction(actionType at, int position, char *data, int length, bool &startSequence, bool mayCoalesce=true);
void BeginUndoAction();
void EndUndoAction();
@@ -185,7 +185,7 @@ public:
bool IsCollectingUndo();
void BeginUndoAction();
void EndUndoAction();
- void AddUndoAction(int token);
+ void AddUndoAction(int token, bool mayCoalesce);
void DeleteUndoHistory();
/// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
diff --git a/src/Document.h b/src/Document.h
index 6c0d9d51c..c0d221d35 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -179,7 +179,7 @@ public:
bool IsCollectingUndo() { return cb.IsCollectingUndo(); }
void BeginUndoAction() { cb.BeginUndoAction(); }
void EndUndoAction() { cb.EndUndoAction(); }
- void AddUndoAction(int token) { cb.AddUndoAction(token); }
+ void AddUndoAction(int token, bool mayCoalesce) { cb.AddUndoAction(token, mayCoalesce); }
void SetSavePoint();
bool IsSavePoint() { return cb.IsSavePoint(); }
const char *BufferPointer() { return cb.BufferPointer(); }
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 77fbb4cec..0c15a8c98 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -8006,7 +8006,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return vs.annotationStyleOffset;
case SCI_ADDUNDOACTION:
- pdoc->AddUndoAction(wParam);
+ pdoc->AddUndoAction(wParam, lParam & UNDO_MAY_COALESCE);
break;
default: