1 // Scintilla source code edit control
2 // CellBuffer.cxx - manages a buffer of cells
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
13 #include "Scintilla.h"
15 #include "CellBuffer.h"
17 MarkerHandleSet::MarkerHandleSet() {
21 MarkerHandleSet::~MarkerHandleSet() {
22 MarkerHandleNumber
*mhn
= root
;
24 MarkerHandleNumber
*mhnToFree
= mhn
;
31 int MarkerHandleSet::Length() {
33 MarkerHandleNumber
*mhn
= root
;
41 int MarkerHandleSet::NumberFromHandle(int handle
) {
42 MarkerHandleNumber
*mhn
= root
;
44 if (mhn
->handle
== handle
) {
52 int MarkerHandleSet::MarkValue() {
54 MarkerHandleNumber
*mhn
= root
;
56 m
|= (1 << mhn
->number
);
62 bool MarkerHandleSet::Contains(int handle
) {
63 MarkerHandleNumber
*mhn
= root
;
65 if (mhn
->handle
== handle
) {
73 bool MarkerHandleSet::InsertHandle(int handle
, int markerNum
) {
74 MarkerHandleNumber
*mhn
= new MarkerHandleNumber
;
78 mhn
->number
= markerNum
;
84 void MarkerHandleSet::RemoveHandle(int handle
) {
85 MarkerHandleNumber
**pmhn
= &root
;
87 MarkerHandleNumber
*mhn
= *pmhn
;
88 if (mhn
->handle
== handle
) {
93 pmhn
= &((*pmhn
)->next
);
97 void MarkerHandleSet::RemoveNumber(int markerNum
) {
98 MarkerHandleNumber
**pmhn
= &root
;
100 MarkerHandleNumber
*mhn
= *pmhn
;
101 if (mhn
->number
== markerNum
) {
106 pmhn
= &((*pmhn
)->next
);
110 void MarkerHandleSet::CombineWith(MarkerHandleSet
*other
) {
111 MarkerHandleNumber
**pmhn
= &root
;
113 pmhn
= &((*pmhn
)->next
);
119 LineVector::LineVector() {
126 LineVector::~LineVector() {
127 for (int line
= 0; line
< lines
; line
++) {
128 delete linesData
[line
].handleSet
;
129 linesData
[line
].handleSet
= 0;
137 void LineVector::Init() {
138 for (int line
= 0; line
< lines
; line
++) {
139 delete linesData
[line
].handleSet
;
140 linesData
[line
].handleSet
= 0;
143 linesData
= new LineData
[static_cast<int>(growSize
)];
151 void LineVector::Expand(int sizeNew
) {
152 LineData
*linesDataNew
= new LineData
[sizeNew
];
154 for (int i
= 0; i
< size
; i
++)
155 linesDataNew
[i
] = linesData
[i
];
156 // Do not delete handleSets here as they are transferred to new linesData
158 linesData
= linesDataNew
;
161 Platform::DebugPrintf("No memory available\n");
166 void LineVector::ExpandLevels(int sizeNew
) {
169 int *levelsNew
= new int[sizeNew
];
172 for (; i
< sizeLevels
; i
++)
173 levelsNew
[i
] = levels
[i
];
174 for (; i
< sizeNew
; i
++)
175 levelsNew
[i
] = SC_FOLDLEVELBASE
;
178 sizeLevels
= sizeNew
;
180 Platform::DebugPrintf("No memory available\n");
185 void LineVector::InsertValue(int pos
, int value
) {
186 //Platform::DebugPrintf("InsertValue[%d] = %d\n", pos, value);
187 if ((lines
+ 2) >= size
) {
188 Expand(size
+ growSize
);
190 ExpandLevels(size
+ growSize
);
194 for (int i
= lines
+ 1; i
> pos
; i
--) {
195 linesData
[i
] = linesData
[i
- 1];
197 linesData
[pos
].startPosition
= value
;
198 linesData
[pos
].handleSet
= 0;
201 void LineVector::SetValue(int pos
, int value
) {
202 //Platform::DebugPrintf("SetValue[%d] = %d\n", pos, value);
203 if ((pos
+ 2) >= size
) {
204 //Platform::DebugPrintf("Resize %d %d\n", size,pos);
205 Expand(pos
+ growSize
);
206 //Platform::DebugPrintf("end Resize %d %d\n", size,pos);
209 ExpandLevels(pos
+ growSize
);
212 linesData
[pos
].startPosition
= value
;
215 void LineVector::Remove(int pos
) {
216 //Platform::DebugPrintf("Remove %d\n", pos);
217 // Retain the markers from the deleted line by oring them into the previous line
219 MergeMarkers(pos
- 1);
221 for (int i
= pos
; i
< lines
; i
++) {
222 linesData
[i
] = linesData
[i
+ 1];
227 int LineVector::LineFromPosition(int pos
) {
228 //Platform::DebugPrintf("LineFromPostion %d lines=%d end = %d\n", pos, lines, linesData[lines].startPosition);
231 //Platform::DebugPrintf("LineFromPosition %d\n", pos);
232 if (pos
>= linesData
[lines
].startPosition
)
238 middle
= (upper
+ lower
+ 1) / 2; // Round high
239 if (pos
< linesData
[middle
].startPosition
) {
244 } while (lower
< upper
);
245 //Platform::DebugPrintf("LineFromPostion %d %d %d\n", pos, lower, linesData[lower].startPosition, linesData[lower > 1 ? lower - 1 : 0].startPosition);
249 int LineVector::AddMark(int line
, int markerNum
) {
251 if (!linesData
[line
].handleSet
) {
252 // Need new structure to hold marker handle
253 linesData
[line
].handleSet
= new MarkerHandleSet
;
254 if (!linesData
[line
].handleSet
)
257 linesData
[line
].handleSet
->InsertHandle(handleCurrent
, markerNum
);
259 return handleCurrent
;
262 void LineVector::MergeMarkers(int pos
) {
263 if (linesData
[pos
].handleSet
|| linesData
[pos
+ 1].handleSet
) {
264 if (linesData
[pos
].handleSet
&& linesData
[pos
+ 1].handleSet
) {
265 linesData
[pos
].handleSet
->CombineWith(linesData
[pos
].handleSet
);
266 linesData
[pos
].handleSet
= 0;
271 void LineVector::DeleteMark(int line
, int markerNum
) {
272 if (linesData
[line
].handleSet
) {
273 if (markerNum
== -1) {
274 delete linesData
[line
].handleSet
;
275 linesData
[line
].handleSet
= 0;
277 linesData
[line
].handleSet
->RemoveNumber(markerNum
);
278 if (linesData
[line
].handleSet
->Length() == 0) {
279 delete linesData
[line
].handleSet
;
280 linesData
[line
].handleSet
= 0;
286 void LineVector::DeleteMarkFromHandle(int markerHandle
) {
287 int line
= LineFromHandle(markerHandle
);
289 linesData
[line
].handleSet
->RemoveHandle(markerHandle
);
290 if (linesData
[line
].handleSet
->Length() == 0) {
291 delete linesData
[line
].handleSet
;
292 linesData
[line
].handleSet
= 0;
297 int LineVector::LineFromHandle(int markerHandle
) {
298 for (int line
= 0; line
< lines
; line
++) {
299 if (linesData
[line
].handleSet
) {
300 if (linesData
[line
].handleSet
->Contains(markerHandle
)) {
319 void Action::Create(actionType at_
, int position_
, char *data_
, int lenData_
) {
321 position
= position_
;
327 void Action::Destroy() {
332 void Action::Grab(Action
*source
) {
335 position
= source
->position
;
338 lenData
= source
->lenData
;
340 // Ownership of source data transferred to this
341 source
->position
= 0;
342 source
->at
= startAction
;
347 // The undo history stores a sequence of user operations that represent the user's view of the
348 // commands executed on the text.
349 // Each user operation contains a sequence of text insertion and text deletion actions.
350 // All the user operations are stored in a list of individual actions with 'start' actions used
351 // as delimiters between user operations.
352 // Initially there is one start action in the history.
353 // As each action is performed, it is recorded in the history. The action may either become
354 // part of the current user operation or may start a new user operation. If it is to be part of the
355 // current operation, then it overwrites the current last action. If it is to be part of a new
356 // operation, it is appended after the current last action.
357 // After writing the new action, a new start action is appended at the end of the history.
358 // The decision of whether to start a new user operation is based upon two factors. If a
359 // compound operation has been explicitly started by calling BeginUndoAction and no matching
360 // EndUndoAction (these calls nest) has been called, then the action is coalesced into the current
361 // operation. If there is no outstanding BeginUndoAction call then a new operation is started
362 // unless it looks as if the new action is caused by the user typing or deleting a stream of text.
363 // Sequences that look like typing or deletion are coalesced into a single user operation.
365 UndoHistory::UndoHistory() {
368 actions
= new Action
[lenActions
];
371 undoSequenceDepth
= 0;
374 actions
[currentAction
].Create(startAction
);
377 UndoHistory::~UndoHistory() {
382 void UndoHistory::EnsureUndoRoom() {
383 //Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, length, currentAction);
384 if (currentAction
>= 2) {
385 // Have to test that there is room for 2 more actions in the array
386 // as two actions may be created by this function
387 if (currentAction
>= (lenActions
- 2)) {
388 // Run out of undo nodes so extend the array
389 int lenActionsNew
= lenActions
* 2;
390 Action
*actionsNew
= new Action
[lenActionsNew
];
393 for (int act
= 0; act
<= currentAction
; act
++)
394 actionsNew
[act
].Grab(&actions
[act
]);
396 lenActions
= lenActionsNew
;
397 actions
= actionsNew
;
402 void UndoHistory::AppendAction(actionType at
, int position
, char *data
, int lengthData
) {
404 //Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, lengthData, currentAction);
405 //Platform::DebugPrintf("^ %d action %d %d\n", actions[currentAction - 1].at,
406 // actions[currentAction - 1].position, actions[currentAction - 1].lenData);
407 if (currentAction
>= 1) {
408 if (0 == undoSequenceDepth
) {
409 // Top level actions may not always be coalesced
410 Action
&actPrevious
= actions
[currentAction
- 1];
411 // See if current action can be coalesced into previous action
412 // Will work if both are inserts or deletes and position is same
413 if (at
!= actPrevious
.at
) {
415 } else if (currentAction
== savePoint
) {
417 } else if ((at
== removeAction
) &&
418 ((position
+ lengthData
* 2) != actPrevious
.position
)) {
419 // Removals must be at same position to coalesce
421 } else if ((at
== insertAction
) &&
422 (position
!= (actPrevious
.position
+ actPrevious
.lenData
*2))) {
423 // Insertions must be immediately after to coalesce
426 //Platform::DebugPrintf("action coalesced\n");
434 actions
[currentAction
].Create(at
, position
, data
, lengthData
);
436 actions
[currentAction
].Create(startAction
);
437 maxAction
= currentAction
;
440 void UndoHistory::BeginUndoAction() {
442 if (undoSequenceDepth
== 0) {
443 if (actions
[currentAction
].at
!= startAction
) {
445 actions
[currentAction
].Create(startAction
);
446 maxAction
= currentAction
;
452 void UndoHistory::EndUndoAction() {
455 if (0 == undoSequenceDepth
) {
456 if (actions
[currentAction
].at
!= startAction
) {
458 actions
[currentAction
].Create(startAction
);
459 maxAction
= currentAction
;
464 void UndoHistory::DropUndoSequence() {
465 undoSequenceDepth
= 0;
468 void UndoHistory::DeleteUndoHistory() {
469 for (int i
= 1; i
< maxAction
; i
++)
470 actions
[i
].Destroy();
473 actions
[currentAction
].Create(startAction
);
477 void UndoHistory::SetSavePoint() {
478 savePoint
= currentAction
;
481 bool UndoHistory::IsSavePoint() const {
482 return savePoint
== currentAction
;
485 bool UndoHistory::CanUndo() const {
486 return (currentAction
> 0) && (maxAction
> 0);
489 int UndoHistory::StartUndo() {
490 // Drop any trailing startAction
491 if (actions
[currentAction
].at
== startAction
&& currentAction
> 0)
494 // Count the steps in this action
495 int act
= currentAction
;
496 while (actions
[act
].at
!= startAction
&& act
> 0) {
499 return currentAction
- act
;
502 const Action
&UndoHistory::UndoStep() {
503 return actions
[currentAction
--];
506 bool UndoHistory::CanRedo() const {
507 return maxAction
> currentAction
;
510 int UndoHistory::StartRedo() {
511 // Drop any leading startAction
512 if (actions
[currentAction
].at
== startAction
&& currentAction
< maxAction
)
515 // Count the steps in this action
516 int act
= currentAction
;
517 while (actions
[act
].at
!= startAction
&& act
< maxAction
) {
520 return act
- currentAction
;
523 const Action
&UndoHistory::RedoStep() {
524 return actions
[currentAction
++];
527 CellBuffer::CellBuffer(int initialLength
) {
528 body
= new char[initialLength
];
529 size
= initialLength
;
532 gaplen
= initialLength
;
533 part2body
= body
+ gaplen
;
535 collectingUndo
= undoCollectAutoStart
;
538 CellBuffer::~CellBuffer() {
543 void CellBuffer::GapTo(int position
) {
544 if (position
== part1len
)
546 if (position
< part1len
) {
547 int diff
= part1len
- position
;
548 //Platform::DebugPrintf("Move gap backwards to %d diff = %d part1len=%d length=%d \n", position,diff, part1len, length);
549 for (int i
= 0; i
< diff
; i
++)
550 body
[part1len
+ gaplen
- i
- 1] = body
[part1len
- i
- 1];
551 } else { // position > part1len
552 int diff
= position
- part1len
;
553 //Platform::DebugPrintf("Move gap forwards to %d diff =%d\n", position,diff);
554 for (int i
= 0; i
< diff
; i
++)
555 body
[part1len
+ i
] = body
[part1len
+ gaplen
+ i
];
558 part2body
= body
+ gaplen
;
561 void CellBuffer::RoomFor(int insertionLength
) {
562 //Platform::DebugPrintf("need room %d %d\n", gaplen, insertionLength);
563 if (gaplen
<= insertionLength
) {
564 //Platform::DebugPrintf("need room %d %d\n", gaplen, insertionLength);
566 int newSize
= size
+ insertionLength
+ 4000;
567 //Platform::DebugPrintf("moved gap %d\n", newSize);
568 char *newBody
= new char[newSize
];
569 memcpy(newBody
, body
, size
);
572 gaplen
+= newSize
- size
;
573 part2body
= body
+ gaplen
;
575 //Platform::DebugPrintf("end need room %d %d - size=%d length=%d\n", gaplen, insertionLength,size,length);
579 // To make it easier to write code that uses ByteAt, a position outside the range of the buffer
580 // can be retrieved. All characters outside the range have the value '\0'.
581 char CellBuffer::ByteAt(int position
) {
582 if (position
< part1len
) {
586 return body
[position
];
589 if (position
>= length
) {
592 return part2body
[position
];
597 void CellBuffer::SetByteAt(int position
, char ch
) {
600 //Platform::DebugPrintf("Bad position %d\n",position);
603 if (position
>= length
+ 11) {
604 Platform::DebugPrintf("Very Bad position %d of %d\n", position
, length
);
608 if (position
>= length
) {
609 //Platform::DebugPrintf("Bad position %d of %d\n",position,length);
613 if (position
< part1len
) {
616 part2body
[position
] = ch
;
620 char CellBuffer::CharAt(int position
) {
621 return ByteAt(position
*2);
624 void CellBuffer::GetCharRange(char *buffer
, int position
, int lengthRetrieve
) {
625 if (lengthRetrieve
< 0)
629 int bytePos
= position
* 2;
630 if ((bytePos
+ lengthRetrieve
* 2) > length
) {
631 Platform::DebugPrintf("Bad GetCharRange %d for %d of %d\n",bytePos
,
632 lengthRetrieve
, length
);
635 GapTo(0); // Move the buffer so its easy to subscript into it
636 char *pb
= part2body
+ bytePos
;
637 while (lengthRetrieve
--) {
643 char CellBuffer::StyleAt(int position
) {
644 return ByteAt(position
*2 + 1);
647 const char *CellBuffer::InsertString(int position
, char *s
, int insertLength
) {
649 // InsertString and DeleteChars are the bottleneck though which all changes occur
651 if (collectingUndo
) {
652 // Save into the undo/redo stack, but only the characters - not the formatting
653 // This takes up about half load time
654 data
= new char[insertLength
/ 2];
655 for (int i
= 0; i
< insertLength
/ 2; i
++) {
658 uh
.AppendAction(insertAction
, position
, data
, insertLength
/ 2);
661 BasicInsertString(position
, s
, insertLength
);
666 void CellBuffer::InsertCharStyle(int position
, char ch
, char style
) {
670 InsertString(position
*2, s
, 2);
673 bool CellBuffer::SetStyleAt(int position
, char style
, char mask
) {
674 char curVal
= ByteAt(position
*2 + 1);
675 if ((curVal
& mask
) != style
) {
676 SetByteAt(position
*2 + 1, (curVal
& ~mask
) | style
);
683 bool CellBuffer::SetStyleFor(int position
, int lengthStyle
, char style
, char mask
) {
684 int bytePos
= position
* 2 + 1;
685 bool changed
= false;
686 while (lengthStyle
--) {
687 char curVal
= ByteAt(bytePos
);
688 if ((curVal
& mask
) != style
) {
689 SetByteAt(bytePos
, (curVal
& ~mask
) | style
);
697 const char *CellBuffer::DeleteChars(int position
, int deleteLength
) {
698 // InsertString and DeleteChars are the bottleneck though which all changes occur
701 if (collectingUndo
) {
702 // Save into the undo/redo stack, but only the characters - not the formatting
703 data
= new char[deleteLength
/ 2];
704 for (int i
= 0; i
< deleteLength
/ 2; i
++) {
705 data
[i
] = ByteAt(position
+ i
* 2);
707 uh
.AppendAction(removeAction
, position
, data
, deleteLength
/ 2);
710 BasicDeleteChars(position
, deleteLength
);
715 int CellBuffer::ByteLength() {
719 int CellBuffer::Length() {
720 return ByteLength() / 2;
723 int CellBuffer::Lines() {
724 //Platform::DebugPrintf("Lines = %d\n", lv.lines);
728 int CellBuffer::LineStart(int line
) {
731 else if (line
> lv
.lines
)
734 return lv
.linesData
[line
].startPosition
;
737 bool CellBuffer::IsReadOnly() {
741 void CellBuffer::SetReadOnly(bool set
) {
745 void CellBuffer::SetSavePoint() {
749 bool CellBuffer::IsSavePoint() {
750 return uh
.IsSavePoint();
753 int CellBuffer::AddMark(int line
, int markerNum
) {
754 if ((line
>= 0) && (line
< lv
.lines
)) {
755 return lv
.AddMark(line
, markerNum
);
760 void CellBuffer::DeleteMark(int line
, int markerNum
) {
761 if ((line
>= 0) && (line
< lv
.lines
)) {
762 lv
.DeleteMark(line
, markerNum
);
766 void CellBuffer::DeleteMarkFromHandle(int markerHandle
) {
767 lv
.DeleteMarkFromHandle(markerHandle
);
770 int CellBuffer::GetMark(int line
) {
771 if ((line
>= 0) && (line
< lv
.lines
) && (lv
.linesData
[line
].handleSet
))
772 return lv
.linesData
[line
].handleSet
->MarkValue();
776 void CellBuffer::DeleteAllMarks(int markerNum
) {
777 for (int line
= 0; line
< lv
.lines
; line
++) {
778 lv
.DeleteMark(line
, markerNum
);
782 int CellBuffer::LineFromHandle(int markerHandle
) {
783 return lv
.LineFromHandle(markerHandle
);
788 void CellBuffer::BasicInsertString(int position
, char *s
, int insertLength
) {
789 //Platform::DebugPrintf("Inserting at %d for %d\n", position, insertLength);
790 if (insertLength
== 0)
792 RoomFor(insertLength
);
795 memcpy(body
+ part1len
, s
, insertLength
);
796 length
+= insertLength
;
797 part1len
+= insertLength
;
798 gaplen
-= insertLength
;
799 part2body
= body
+ gaplen
;
801 int lineInsert
= lv
.LineFromPosition(position
/ 2) + 1;
802 // Point all the lines after the insertion point further along in the buffer
803 for (int lineAfter
= lineInsert
; lineAfter
<= lv
.lines
; lineAfter
++) {
804 lv
.linesData
[lineAfter
].startPosition
+= insertLength
/ 2;
807 if ((position
- 2) >= 0)
808 chPrev
= ByteAt(position
- 2);
810 if ((position
+ insertLength
) < length
)
811 chAfter
= ByteAt(position
+ insertLength
);
812 if (chPrev
== '\r' && chAfter
== '\n') {
813 //Platform::DebugPrintf("Splitting a crlf pair at %d\n", lineInsert);
814 // Splitting up a crlf pair at position
815 lv
.InsertValue(lineInsert
, position
/ 2);
819 for (int i
= 0; i
< insertLength
; i
+= 2) {
822 //Platform::DebugPrintf("Inserting cr at %d\n", lineInsert);
823 lv
.InsertValue(lineInsert
, (position
+ i
) / 2 + 1);
825 } else if (ch
== '\n') {
826 if (chPrev
== '\r') {
827 //Platform::DebugPrintf("Patching cr before lf at %d\n", lineInsert-1);
828 // Patch up what was end of line
829 lv
.SetValue(lineInsert
- 1, (position
+ i
) / 2 + 1);
831 //Platform::DebugPrintf("Inserting lf at %d\n", lineInsert);
832 lv
.InsertValue(lineInsert
, (position
+ i
) / 2 + 1);
838 // Joining two lines where last insertion is cr and following text starts with lf
839 if (chAfter
== '\n') {
841 //Platform::DebugPrintf("Joining cr before lf at %d\n", lineInsert-1);
842 // End of line already in buffer so drop the newly created one
843 lv
.Remove(lineInsert
- 1);
848 void CellBuffer::BasicDeleteChars(int position
, int deleteLength
) {
849 //Platform::DebugPrintf("Deleting at %d for %d\n", position, deleteLength);
850 if (deleteLength
== 0)
853 if ((position
== 0) && (deleteLength
== length
)) {
854 // If whole buffer is being deleted, faster to reinitialise lines data
855 // than to delete each line.
856 //printf("Whole buffer being deleted\n");
859 // Have to fix up line positions before doing deletion as looking at text in buffer
860 // to work out which lines have been removed
862 int lineRemove
= lv
.LineFromPosition(position
/ 2) + 1;
863 // Point all the lines after the insertion point further along in the buffer
864 for (int lineAfter
= lineRemove
; lineAfter
<= lv
.lines
; lineAfter
++) {
865 lv
.linesData
[lineAfter
].startPosition
-= deleteLength
/ 2;
869 chPrev
= ByteAt(position
- 2);
870 char chBefore
= chPrev
;
872 if (position
< length
)
873 chNext
= ByteAt(position
);
874 bool ignoreNL
= false;
875 if (chPrev
== '\r' && chNext
== '\n') {
876 //Platform::DebugPrintf("Deleting lf after cr, move line end to cr at %d\n", lineRemove);
878 lv
.SetValue(lineRemove
, position
/ 2);
880 ignoreNL
= true; // First \n is not real deletion
884 for (int i
= 0; i
< deleteLength
; i
+= 2) {
886 if ((position
+ i
+ 2) < length
)
887 chNext
= ByteAt(position
+ i
+ 2);
888 //Platform::DebugPrintf("Deleting %d %x\n", i, ch);
890 if (chNext
!= '\n') {
891 //Platform::DebugPrintf("Removing cr end of line\n");
892 lv
.Remove(lineRemove
);
894 } else if ((ch
== '\n') && !ignoreNL
) {
895 //Platform::DebugPrintf("Removing lf end of line\n");
896 lv
.Remove(lineRemove
);
897 ignoreNL
= false; // Further \n are not real deletions
902 // May have to fix up end if last deletion causes cr to be next to lf
903 // or removes one of a crlf pair
905 if ((position
+ deleteLength
) < length
)
906 chAfter
= ByteAt(position
+ deleteLength
);
907 if (chBefore
== '\r' && chAfter
== '\n') {
908 //d.printf("Joining cr before lf at %d\n", lineRemove);
909 // Using lineRemove-1 as cr ended line before start of deletion
910 lv
.Remove(lineRemove
- 1);
911 lv
.SetValue(lineRemove
- 1, position
/ 2 + 1);
915 length
-= deleteLength
;
916 gaplen
+= deleteLength
;
917 part2body
= body
+ gaplen
;
920 undoCollectionType
CellBuffer::SetUndoCollection(undoCollectionType collectUndo
) {
921 collectingUndo
= collectUndo
;
922 uh
.DropUndoSequence();
923 return collectingUndo
;
926 bool CellBuffer::IsCollectingUndo() {
927 return collectingUndo
;
930 void CellBuffer::BeginUndoAction() {
931 uh
.BeginUndoAction();
934 void CellBuffer::EndUndoAction() {
938 void CellBuffer::DeleteUndoHistory() {
939 uh
.DeleteUndoHistory();
942 bool CellBuffer::CanUndo() {
943 return (!readOnly
) && (uh
.CanUndo());
946 int CellBuffer::StartUndo() {
947 return uh
.StartUndo();
950 const Action
&CellBuffer::UndoStep() {
951 const Action
&actionStep
= uh
.UndoStep();
952 if (actionStep
.at
== insertAction
) {
953 BasicDeleteChars(actionStep
.position
, actionStep
.lenData
*2);
954 } else if (actionStep
.at
== removeAction
) {
955 char *styledData
= new char[actionStep
.lenData
* 2];
956 for (int i
= 0; i
< actionStep
.lenData
; i
++) {
957 styledData
[i
*2] = actionStep
.data
[i
];
958 styledData
[i
*2+1] = 0;
960 BasicInsertString(actionStep
.position
, styledData
, actionStep
.lenData
*2);
966 bool CellBuffer::CanRedo() {
967 return (!readOnly
) && (uh
.CanRedo());
970 int CellBuffer::StartRedo() {
971 return uh
.StartRedo();
974 const Action
&CellBuffer::RedoStep() {
975 const Action
&actionStep
= uh
.RedoStep();
976 if (actionStep
.at
== insertAction
) {
977 char *styledData
= new char[actionStep
.lenData
* 2];
978 for (int i
= 0; i
< actionStep
.lenData
; i
++) {
979 styledData
[i
*2] = actionStep
.data
[i
];
980 styledData
[i
*2+1] = 0;
982 BasicInsertString(actionStep
.position
, styledData
, actionStep
.lenData
*2);
984 } else if (actionStep
.at
== removeAction
) {
985 BasicDeleteChars(actionStep
.position
, actionStep
.lenData
*2);
990 int CellBuffer::SetLineState(int line
, int state
) {
991 int stateOld
= lineStates
[line
];
992 lineStates
[line
] = state
;
996 int CellBuffer::GetLineState(int line
) {
997 return lineStates
[line
];
1000 int CellBuffer::GetMaxLineState() {
1001 return lineStates
.Length();
1004 int CellBuffer::SetLevel(int line
, int level
) {
1006 if ((line
>= 0) && (line
< lv
.lines
)) {
1010 prev
= lv
.levels
[line
];
1011 if (lv
.levels
[line
] != level
) {
1012 lv
.levels
[line
] = level
;
1018 int CellBuffer::GetLevel(int line
) {
1019 if (lv
.levels
&& (line
>= 0) && (line
< lv
.lines
)) {
1020 return lv
.levels
[line
];
1022 return SC_FOLDLEVELBASE
;