Merge pull request #826 from kugel-/doxygen-fixes2
[geany-mirror.git] / scintilla / src / CellBuffer.cxx
blobf43a0c3025209c1c11447846404711c93a7110f1
1 // Scintilla source code edit control
2 /** @file CellBuffer.cxx
3 ** Manages a buffer of cells.
4 **/
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <stdarg.h>
13 #include <stdexcept>
14 #include <algorithm>
16 #include "Platform.h"
18 #include "Scintilla.h"
19 #include "Position.h"
20 #include "SplitVector.h"
21 #include "Partitioning.h"
22 #include "CellBuffer.h"
23 #include "UniConversion.h"
25 #ifdef SCI_NAMESPACE
26 using namespace Scintilla;
27 #endif
29 LineVector::LineVector() : starts(256), perLine(0) {
30 Init();
33 LineVector::~LineVector() {
34 starts.DeleteAll();
37 void LineVector::Init() {
38 starts.DeleteAll();
39 if (perLine) {
40 perLine->Init();
44 void LineVector::SetPerLine(PerLine *pl) {
45 perLine = pl;
48 void LineVector::InsertText(int line, int delta) {
49 starts.InsertText(line, delta);
52 void LineVector::InsertLine(int line, int position, bool lineStart) {
53 starts.InsertPartition(line, position);
54 if (perLine) {
55 if ((line > 0) && lineStart)
56 line--;
57 perLine->InsertLine(line);
61 void LineVector::SetLineStart(int line, int position) {
62 starts.SetPartitionStartPosition(line, position);
65 void LineVector::RemoveLine(int line) {
66 starts.RemovePartition(line);
67 if (perLine) {
68 perLine->RemoveLine(line);
72 int LineVector::LineFromPosition(int pos) const {
73 return starts.PartitionFromPosition(pos);
76 Action::Action() {
77 at = startAction;
78 position = 0;
79 data = 0;
80 lenData = 0;
81 mayCoalesce = false;
84 Action::~Action() {
85 Destroy();
88 void Action::Create(actionType at_, int position_, const char *data_, int lenData_, bool mayCoalesce_) {
89 delete []data;
90 data = NULL;
91 position = position_;
92 at = at_;
93 if (lenData_) {
94 data = new char[lenData_];
95 memcpy(data, data_, lenData_);
97 lenData = lenData_;
98 mayCoalesce = mayCoalesce_;
101 void Action::Destroy() {
102 delete []data;
103 data = 0;
106 void Action::Grab(Action *source) {
107 delete []data;
109 position = source->position;
110 at = source->at;
111 data = source->data;
112 lenData = source->lenData;
113 mayCoalesce = source->mayCoalesce;
115 // Ownership of source data transferred to this
116 source->position = 0;
117 source->at = startAction;
118 source->data = 0;
119 source->lenData = 0;
120 source->mayCoalesce = true;
123 // The undo history stores a sequence of user operations that represent the user's view of the
124 // commands executed on the text.
125 // Each user operation contains a sequence of text insertion and text deletion actions.
126 // All the user operations are stored in a list of individual actions with 'start' actions used
127 // as delimiters between user operations.
128 // Initially there is one start action in the history.
129 // As each action is performed, it is recorded in the history. The action may either become
130 // part of the current user operation or may start a new user operation. If it is to be part of the
131 // current operation, then it overwrites the current last action. If it is to be part of a new
132 // operation, it is appended after the current last action.
133 // After writing the new action, a new start action is appended at the end of the history.
134 // The decision of whether to start a new user operation is based upon two factors. If a
135 // compound operation has been explicitly started by calling BeginUndoAction and no matching
136 // EndUndoAction (these calls nest) has been called, then the action is coalesced into the current
137 // operation. If there is no outstanding BeginUndoAction call then a new operation is started
138 // unless it looks as if the new action is caused by the user typing or deleting a stream of text.
139 // Sequences that look like typing or deletion are coalesced into a single user operation.
141 UndoHistory::UndoHistory() {
143 lenActions = 100;
144 actions = new Action[lenActions];
145 maxAction = 0;
146 currentAction = 0;
147 undoSequenceDepth = 0;
148 savePoint = 0;
149 tentativePoint = -1;
151 actions[currentAction].Create(startAction);
154 UndoHistory::~UndoHistory() {
155 delete []actions;
156 actions = 0;
159 void UndoHistory::EnsureUndoRoom() {
160 // Have to test that there is room for 2 more actions in the array
161 // as two actions may be created by the calling function
162 if (currentAction >= (lenActions - 2)) {
163 // Run out of undo nodes so extend the array
164 int lenActionsNew = lenActions * 2;
165 Action *actionsNew = new Action[lenActionsNew];
166 for (int act = 0; act <= currentAction; act++)
167 actionsNew[act].Grab(&actions[act]);
168 delete []actions;
169 lenActions = lenActionsNew;
170 actions = actionsNew;
174 const char *UndoHistory::AppendAction(actionType at, int position, const char *data, int lengthData,
175 bool &startSequence, bool mayCoalesce) {
176 EnsureUndoRoom();
177 //Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, lengthData, currentAction);
178 //Platform::DebugPrintf("^ %d action %d %d\n", actions[currentAction - 1].at,
179 // actions[currentAction - 1].position, actions[currentAction - 1].lenData);
180 if (currentAction < savePoint) {
181 savePoint = -1;
183 int oldCurrentAction = currentAction;
184 if (currentAction >= 1) {
185 if (0 == undoSequenceDepth) {
186 // Top level actions may not always be coalesced
187 int targetAct = -1;
188 const Action *actPrevious = &(actions[currentAction + targetAct]);
189 // Container actions may forward the coalesce state of Scintilla Actions.
190 while ((actPrevious->at == containerAction) && actPrevious->mayCoalesce) {
191 targetAct--;
192 actPrevious = &(actions[currentAction + targetAct]);
194 // See if current action can be coalesced into previous action
195 // Will work if both are inserts or deletes and position is same
196 #if defined(_MSC_VER) && defined(_PREFAST_)
197 // Visual Studio 2013 Code Analysis wrongly believes actions can be NULL at its next reference
198 __analysis_assume(actions);
199 #endif
200 if ((currentAction == savePoint) || (currentAction == tentativePoint)) {
201 currentAction++;
202 } else if (!actions[currentAction].mayCoalesce) {
203 // Not allowed to coalesce if this set
204 currentAction++;
205 } else if (!mayCoalesce || !actPrevious->mayCoalesce) {
206 currentAction++;
207 } else if (at == containerAction || actions[currentAction].at == containerAction) {
208 ; // A coalescible containerAction
209 } else if ((at != actPrevious->at) && (actPrevious->at != startAction)) {
210 currentAction++;
211 } else if ((at == insertAction) &&
212 (position != (actPrevious->position + actPrevious->lenData))) {
213 // Insertions must be immediately after to coalesce
214 currentAction++;
215 } else if (at == removeAction) {
216 if ((lengthData == 1) || (lengthData == 2)) {
217 if ((position + lengthData) == actPrevious->position) {
218 ; // Backspace -> OK
219 } else if (position == actPrevious->position) {
220 ; // Delete -> OK
221 } else {
222 // Removals must be at same position to coalesce
223 currentAction++;
225 } else {
226 // Removals must be of one character to coalesce
227 currentAction++;
229 } else {
230 // Action coalesced.
233 } else {
234 // Actions not at top level are always coalesced unless this is after return to top level
235 if (!actions[currentAction].mayCoalesce)
236 currentAction++;
238 } else {
239 currentAction++;
241 startSequence = oldCurrentAction != currentAction;
242 int actionWithData = currentAction;
243 actions[currentAction].Create(at, position, data, lengthData, mayCoalesce);
244 currentAction++;
245 actions[currentAction].Create(startAction);
246 maxAction = currentAction;
247 return actions[actionWithData].data;
250 void UndoHistory::BeginUndoAction() {
251 EnsureUndoRoom();
252 if (undoSequenceDepth == 0) {
253 if (actions[currentAction].at != startAction) {
254 currentAction++;
255 actions[currentAction].Create(startAction);
256 maxAction = currentAction;
258 actions[currentAction].mayCoalesce = false;
260 undoSequenceDepth++;
263 void UndoHistory::EndUndoAction() {
264 PLATFORM_ASSERT(undoSequenceDepth > 0);
265 EnsureUndoRoom();
266 undoSequenceDepth--;
267 if (0 == undoSequenceDepth) {
268 if (actions[currentAction].at != startAction) {
269 currentAction++;
270 actions[currentAction].Create(startAction);
271 maxAction = currentAction;
273 actions[currentAction].mayCoalesce = false;
277 void UndoHistory::DropUndoSequence() {
278 undoSequenceDepth = 0;
281 void UndoHistory::DeleteUndoHistory() {
282 for (int i = 1; i < maxAction; i++)
283 actions[i].Destroy();
284 maxAction = 0;
285 currentAction = 0;
286 actions[currentAction].Create(startAction);
287 savePoint = 0;
288 tentativePoint = -1;
291 void UndoHistory::SetSavePoint() {
292 savePoint = currentAction;
295 bool UndoHistory::IsSavePoint() const {
296 return savePoint == currentAction;
299 void UndoHistory::TentativeStart() {
300 tentativePoint = currentAction;
303 void UndoHistory::TentativeCommit() {
304 tentativePoint = -1;
305 // Truncate undo history
306 maxAction = currentAction;
309 int UndoHistory::TentativeSteps() {
310 // Drop any trailing startAction
311 if (actions[currentAction].at == startAction && currentAction > 0)
312 currentAction--;
313 if (tentativePoint >= 0)
314 return currentAction - tentativePoint;
315 else
316 return -1;
319 bool UndoHistory::CanUndo() const {
320 return (currentAction > 0) && (maxAction > 0);
323 int UndoHistory::StartUndo() {
324 // Drop any trailing startAction
325 if (actions[currentAction].at == startAction && currentAction > 0)
326 currentAction--;
328 // Count the steps in this action
329 int act = currentAction;
330 while (actions[act].at != startAction && act > 0) {
331 act--;
333 return currentAction - act;
336 const Action &UndoHistory::GetUndoStep() const {
337 return actions[currentAction];
340 void UndoHistory::CompletedUndoStep() {
341 currentAction--;
344 bool UndoHistory::CanRedo() const {
345 return maxAction > currentAction;
348 int UndoHistory::StartRedo() {
349 // Drop any leading startAction
350 if (actions[currentAction].at == startAction && currentAction < maxAction)
351 currentAction++;
353 // Count the steps in this action
354 int act = currentAction;
355 while (actions[act].at != startAction && act < maxAction) {
356 act++;
358 return act - currentAction;
361 const Action &UndoHistory::GetRedoStep() const {
362 return actions[currentAction];
365 void UndoHistory::CompletedRedoStep() {
366 currentAction++;
369 CellBuffer::CellBuffer() {
370 readOnly = false;
371 utf8LineEnds = 0;
372 collectingUndo = true;
375 CellBuffer::~CellBuffer() {
378 char CellBuffer::CharAt(int position) const {
379 return substance.ValueAt(position);
382 void CellBuffer::GetCharRange(char *buffer, int position, int lengthRetrieve) const {
383 if (lengthRetrieve <= 0)
384 return;
385 if (position < 0)
386 return;
387 if ((position + lengthRetrieve) > substance.Length()) {
388 Platform::DebugPrintf("Bad GetCharRange %d for %d of %d\n", position,
389 lengthRetrieve, substance.Length());
390 return;
392 substance.GetRange(buffer, position, lengthRetrieve);
395 char CellBuffer::StyleAt(int position) const {
396 return style.ValueAt(position);
399 void CellBuffer::GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const {
400 if (lengthRetrieve < 0)
401 return;
402 if (position < 0)
403 return;
404 if ((position + lengthRetrieve) > style.Length()) {
405 Platform::DebugPrintf("Bad GetStyleRange %d for %d of %d\n", position,
406 lengthRetrieve, style.Length());
407 return;
409 style.GetRange(reinterpret_cast<char *>(buffer), position, lengthRetrieve);
412 const char *CellBuffer::BufferPointer() {
413 return substance.BufferPointer();
416 const char *CellBuffer::RangePointer(int position, int rangeLength) {
417 return substance.RangePointer(position, rangeLength);
420 int CellBuffer::GapPosition() const {
421 return substance.GapPosition();
424 // The char* returned is to an allocation owned by the undo history
425 const char *CellBuffer::InsertString(int position, const char *s, int insertLength, bool &startSequence) {
426 // InsertString and DeleteChars are the bottleneck though which all changes occur
427 const char *data = s;
428 if (!readOnly) {
429 if (collectingUndo) {
430 // Save into the undo/redo stack, but only the characters - not the formatting
431 // This takes up about half load time
432 data = uh.AppendAction(insertAction, position, s, insertLength, startSequence);
435 BasicInsertString(position, s, insertLength);
437 return data;
440 bool CellBuffer::SetStyleAt(int position, char styleValue) {
441 char curVal = style.ValueAt(position);
442 if (curVal != styleValue) {
443 style.SetValueAt(position, styleValue);
444 return true;
445 } else {
446 return false;
450 bool CellBuffer::SetStyleFor(int position, int lengthStyle, char styleValue) {
451 bool changed = false;
452 PLATFORM_ASSERT(lengthStyle == 0 ||
453 (lengthStyle > 0 && lengthStyle + position <= style.Length()));
454 while (lengthStyle--) {
455 char curVal = style.ValueAt(position);
456 if (curVal != styleValue) {
457 style.SetValueAt(position, styleValue);
458 changed = true;
460 position++;
462 return changed;
465 // The char* returned is to an allocation owned by the undo history
466 const char *CellBuffer::DeleteChars(int position, int deleteLength, bool &startSequence) {
467 // InsertString and DeleteChars are the bottleneck though which all changes occur
468 PLATFORM_ASSERT(deleteLength > 0);
469 const char *data = 0;
470 if (!readOnly) {
471 if (collectingUndo) {
472 // Save into the undo/redo stack, but only the characters - not the formatting
473 // The gap would be moved to position anyway for the deletion so this doesn't cost extra
474 data = substance.RangePointer(position, deleteLength);
475 data = uh.AppendAction(removeAction, position, data, deleteLength, startSequence);
478 BasicDeleteChars(position, deleteLength);
480 return data;
483 int CellBuffer::Length() const {
484 return substance.Length();
487 void CellBuffer::Allocate(int newSize) {
488 substance.ReAllocate(newSize);
489 style.ReAllocate(newSize);
492 void CellBuffer::SetLineEndTypes(int utf8LineEnds_) {
493 if (utf8LineEnds != utf8LineEnds_) {
494 utf8LineEnds = utf8LineEnds_;
495 ResetLineEnds();
499 void CellBuffer::SetPerLine(PerLine *pl) {
500 lv.SetPerLine(pl);
503 int CellBuffer::Lines() const {
504 return lv.Lines();
507 int CellBuffer::LineStart(int line) const {
508 if (line < 0)
509 return 0;
510 else if (line >= Lines())
511 return Length();
512 else
513 return lv.LineStart(line);
516 bool CellBuffer::IsReadOnly() const {
517 return readOnly;
520 void CellBuffer::SetReadOnly(bool set) {
521 readOnly = set;
524 void CellBuffer::SetSavePoint() {
525 uh.SetSavePoint();
528 bool CellBuffer::IsSavePoint() const {
529 return uh.IsSavePoint();
532 void CellBuffer::TentativeStart() {
533 uh.TentativeStart();
536 void CellBuffer::TentativeCommit() {
537 uh.TentativeCommit();
540 int CellBuffer::TentativeSteps() {
541 return uh.TentativeSteps();
544 bool CellBuffer::TentativeActive() const {
545 return uh.TentativeActive();
548 // Without undo
550 void CellBuffer::InsertLine(int line, int position, bool lineStart) {
551 lv.InsertLine(line, position, lineStart);
554 void CellBuffer::RemoveLine(int line) {
555 lv.RemoveLine(line);
558 bool CellBuffer::UTF8LineEndOverlaps(int position) const {
559 unsigned char bytes[] = {
560 static_cast<unsigned char>(substance.ValueAt(position-2)),
561 static_cast<unsigned char>(substance.ValueAt(position-1)),
562 static_cast<unsigned char>(substance.ValueAt(position)),
563 static_cast<unsigned char>(substance.ValueAt(position+1)),
565 return UTF8IsSeparator(bytes) || UTF8IsSeparator(bytes+1) || UTF8IsNEL(bytes+1);
568 void CellBuffer::ResetLineEnds() {
569 // Reinitialize line data -- too much work to preserve
570 lv.Init();
572 int position = 0;
573 int length = Length();
574 int lineInsert = 1;
575 bool atLineStart = true;
576 lv.InsertText(lineInsert-1, length);
577 unsigned char chBeforePrev = 0;
578 unsigned char chPrev = 0;
579 for (int i = 0; i < length; i++) {
580 unsigned char ch = substance.ValueAt(position + i);
581 if (ch == '\r') {
582 InsertLine(lineInsert, (position + i) + 1, atLineStart);
583 lineInsert++;
584 } else if (ch == '\n') {
585 if (chPrev == '\r') {
586 // Patch up what was end of line
587 lv.SetLineStart(lineInsert - 1, (position + i) + 1);
588 } else {
589 InsertLine(lineInsert, (position + i) + 1, atLineStart);
590 lineInsert++;
592 } else if (utf8LineEnds) {
593 unsigned char back3[3] = {chBeforePrev, chPrev, ch};
594 if (UTF8IsSeparator(back3) || UTF8IsNEL(back3+1)) {
595 InsertLine(lineInsert, (position + i) + 1, atLineStart);
596 lineInsert++;
599 chBeforePrev = chPrev;
600 chPrev = ch;
604 void CellBuffer::BasicInsertString(int position, const char *s, int insertLength) {
605 if (insertLength == 0)
606 return;
607 PLATFORM_ASSERT(insertLength > 0);
609 unsigned char chAfter = substance.ValueAt(position);
610 bool breakingUTF8LineEnd = false;
611 if (utf8LineEnds && UTF8IsTrailByte(chAfter)) {
612 breakingUTF8LineEnd = UTF8LineEndOverlaps(position);
615 substance.InsertFromArray(position, s, 0, insertLength);
616 style.InsertValue(position, insertLength, 0);
618 int lineInsert = lv.LineFromPosition(position) + 1;
619 bool atLineStart = lv.LineStart(lineInsert-1) == position;
620 // Point all the lines after the insertion point further along in the buffer
621 lv.InsertText(lineInsert-1, insertLength);
622 unsigned char chBeforePrev = substance.ValueAt(position - 2);
623 unsigned char chPrev = substance.ValueAt(position - 1);
624 if (chPrev == '\r' && chAfter == '\n') {
625 // Splitting up a crlf pair at position
626 InsertLine(lineInsert, position, false);
627 lineInsert++;
629 if (breakingUTF8LineEnd) {
630 RemoveLine(lineInsert);
632 unsigned char ch = ' ';
633 for (int i = 0; i < insertLength; i++) {
634 ch = s[i];
635 if (ch == '\r') {
636 InsertLine(lineInsert, (position + i) + 1, atLineStart);
637 lineInsert++;
638 } else if (ch == '\n') {
639 if (chPrev == '\r') {
640 // Patch up what was end of line
641 lv.SetLineStart(lineInsert - 1, (position + i) + 1);
642 } else {
643 InsertLine(lineInsert, (position + i) + 1, atLineStart);
644 lineInsert++;
646 } else if (utf8LineEnds) {
647 unsigned char back3[3] = {chBeforePrev, chPrev, ch};
648 if (UTF8IsSeparator(back3) || UTF8IsNEL(back3+1)) {
649 InsertLine(lineInsert, (position + i) + 1, atLineStart);
650 lineInsert++;
653 chBeforePrev = chPrev;
654 chPrev = ch;
656 // Joining two lines where last insertion is cr and following substance starts with lf
657 if (chAfter == '\n') {
658 if (ch == '\r') {
659 // End of line already in buffer so drop the newly created one
660 RemoveLine(lineInsert - 1);
662 } else if (utf8LineEnds && !UTF8IsAscii(chAfter)) {
663 // May have end of UTF-8 line end in buffer and start in insertion
664 for (int j = 0; j < UTF8SeparatorLength-1; j++) {
665 unsigned char chAt = substance.ValueAt(position + insertLength + j);
666 unsigned char back3[3] = {chBeforePrev, chPrev, chAt};
667 if (UTF8IsSeparator(back3)) {
668 InsertLine(lineInsert, (position + insertLength + j) + 1, atLineStart);
669 lineInsert++;
671 if ((j == 0) && UTF8IsNEL(back3+1)) {
672 InsertLine(lineInsert, (position + insertLength + j) + 1, atLineStart);
673 lineInsert++;
675 chBeforePrev = chPrev;
676 chPrev = chAt;
681 void CellBuffer::BasicDeleteChars(int position, int deleteLength) {
682 if (deleteLength == 0)
683 return;
685 if ((position == 0) && (deleteLength == substance.Length())) {
686 // If whole buffer is being deleted, faster to reinitialise lines data
687 // than to delete each line.
688 lv.Init();
689 } else {
690 // Have to fix up line positions before doing deletion as looking at text in buffer
691 // to work out which lines have been removed
693 int lineRemove = lv.LineFromPosition(position) + 1;
694 lv.InsertText(lineRemove-1, - (deleteLength));
695 unsigned char chPrev = substance.ValueAt(position - 1);
696 unsigned char chBefore = chPrev;
697 unsigned char chNext = substance.ValueAt(position);
698 bool ignoreNL = false;
699 if (chPrev == '\r' && chNext == '\n') {
700 // Move back one
701 lv.SetLineStart(lineRemove, position);
702 lineRemove++;
703 ignoreNL = true; // First \n is not real deletion
705 if (utf8LineEnds && UTF8IsTrailByte(chNext)) {
706 if (UTF8LineEndOverlaps(position)) {
707 RemoveLine(lineRemove);
711 unsigned char ch = chNext;
712 for (int i = 0; i < deleteLength; i++) {
713 chNext = substance.ValueAt(position + i + 1);
714 if (ch == '\r') {
715 if (chNext != '\n') {
716 RemoveLine(lineRemove);
718 } else if (ch == '\n') {
719 if (ignoreNL) {
720 ignoreNL = false; // Further \n are real deletions
721 } else {
722 RemoveLine(lineRemove);
724 } else if (utf8LineEnds) {
725 if (!UTF8IsAscii(ch)) {
726 unsigned char next3[3] = {ch, chNext,
727 static_cast<unsigned char>(substance.ValueAt(position + i + 2))};
728 if (UTF8IsSeparator(next3) || UTF8IsNEL(next3)) {
729 RemoveLine(lineRemove);
734 ch = chNext;
736 // May have to fix up end if last deletion causes cr to be next to lf
737 // or removes one of a crlf pair
738 char chAfter = substance.ValueAt(position + deleteLength);
739 if (chBefore == '\r' && chAfter == '\n') {
740 // Using lineRemove-1 as cr ended line before start of deletion
741 RemoveLine(lineRemove - 1);
742 lv.SetLineStart(lineRemove - 1, position + 1);
745 substance.DeleteRange(position, deleteLength);
746 style.DeleteRange(position, deleteLength);
749 bool CellBuffer::SetUndoCollection(bool collectUndo) {
750 collectingUndo = collectUndo;
751 uh.DropUndoSequence();
752 return collectingUndo;
755 bool CellBuffer::IsCollectingUndo() const {
756 return collectingUndo;
759 void CellBuffer::BeginUndoAction() {
760 uh.BeginUndoAction();
763 void CellBuffer::EndUndoAction() {
764 uh.EndUndoAction();
767 void CellBuffer::AddUndoAction(int token, bool mayCoalesce) {
768 bool startSequence;
769 uh.AppendAction(containerAction, token, 0, 0, startSequence, mayCoalesce);
772 void CellBuffer::DeleteUndoHistory() {
773 uh.DeleteUndoHistory();
776 bool CellBuffer::CanUndo() const {
777 return uh.CanUndo();
780 int CellBuffer::StartUndo() {
781 return uh.StartUndo();
784 const Action &CellBuffer::GetUndoStep() const {
785 return uh.GetUndoStep();
788 void CellBuffer::PerformUndoStep() {
789 const Action &actionStep = uh.GetUndoStep();
790 if (actionStep.at == insertAction) {
791 if (substance.Length() < actionStep.lenData) {
792 throw std::runtime_error(
793 "CellBuffer::PerformUndoStep: deletion must be less than document length.");
795 BasicDeleteChars(actionStep.position, actionStep.lenData);
796 } else if (actionStep.at == removeAction) {
797 BasicInsertString(actionStep.position, actionStep.data, actionStep.lenData);
799 uh.CompletedUndoStep();
802 bool CellBuffer::CanRedo() const {
803 return uh.CanRedo();
806 int CellBuffer::StartRedo() {
807 return uh.StartRedo();
810 const Action &CellBuffer::GetRedoStep() const {
811 return uh.GetRedoStep();
814 void CellBuffer::PerformRedoStep() {
815 const Action &actionStep = uh.GetRedoStep();
816 if (actionStep.at == insertAction) {
817 BasicInsertString(actionStep.position, actionStep.data, actionStep.lenData);
818 } else if (actionStep.at == removeAction) {
819 BasicDeleteChars(actionStep.position, actionStep.lenData);
821 uh.CompletedRedoStep();