diff options
author | nyamatongwe <unknown> | 2009-04-19 09:38:40 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2009-04-19 09:38:40 +0000 |
commit | bbf8cac83a0fbba3b68a17d119a559ecd521997a (patch) | |
tree | 4dab662fa7dea25f6329508715bbde47f4f1bd31 /src | |
parent | e59f78d0a04cf7c9a2b422da634c0b02ef88ee31 (diff) | |
download | scintilla-mirror-bbf8cac83a0fbba3b68a17d119a559ecd521997a.tar.gz |
Added UNDO_MAY_COALESCE flag to AddUndoAction.
Diffstat (limited to 'src')
-rw-r--r-- | src/CellBuffer.cxx | 39 | ||||
-rw-r--r-- | src/CellBuffer.h | 4 | ||||
-rw-r--r-- | src/Document.h | 2 | ||||
-rw-r--r-- | src/Editor.cxx | 2 |
4 files changed, 27 insertions, 20 deletions
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: |