1 // Scintilla source code edit control
3 ** Manages the text of the document.
5 // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
15 // Interface to per-line data that wants to see each line insertion and deletion
19 virtual void Init()=0;
20 virtual void InsertLine(int line
)=0;
21 virtual void RemoveLine(int line
)=0;
25 * The line vector contains information about each of the lines in a cell buffer.
37 void SetPerLine(PerLine
*pl
);
39 void InsertText(int line
, int delta
);
40 void InsertLine(int line
, int position
, bool lineStart
);
41 void SetLineStart(int line
, int position
);
42 void RemoveLine(int line
);
44 return starts
.Partitions();
46 int LineFromPosition(int pos
) const;
47 int LineStart(int line
) const {
48 return starts
.PositionFromPartition(line
);
52 enum actionType
{ insertAction
, removeAction
, startAction
, containerAction
};
55 * Actions are used to store all the information required to perform one undo/redo step.
67 void Create(actionType at_
, int position_
=0, const char *data_
=0, int lenData_
=0, bool mayCoalesce_
=true);
69 void Grab(Action
*source
);
80 int undoSequenceDepth
;
84 void EnsureUndoRoom();
86 // Private so UndoHistory objects can not be copied
87 UndoHistory(const UndoHistory
&);
93 const char *AppendAction(actionType at
, int position
, const char *data
, int length
, bool &startSequence
, bool mayCoalesce
=true);
95 void BeginUndoAction();
97 void DropUndoSequence();
98 void DeleteUndoHistory();
100 /// The save point is a marker in the undo stack where the container has stated that
101 /// the buffer was saved. Undo and redo can move over the save point.
103 bool IsSavePoint() const;
105 // Tentative actions are used for input composition so that it can be undone cleanly
106 void TentativeStart();
107 void TentativeCommit();
108 bool TentativeActive() const { return tentativePoint
>= 0; }
109 int TentativeSteps();
111 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
112 /// called that many times. Similarly for redo.
113 bool CanUndo() const;
115 const Action
&GetUndoStep() const;
116 void CompletedUndoStep();
117 bool CanRedo() const;
119 const Action
&GetRedoStep() const;
120 void CompletedRedoStep();
124 * Holder for an expandable array of characters that supports undo and line markers.
125 * Based on article "Data Structures in a Bit-Mapped Text Editor"
126 * by Wilfred J. Hansen, Byte January 1987, page 183.
130 SplitVector
<char> substance
;
131 SplitVector
<char> style
;
140 bool UTF8LineEndOverlaps(int position
) const;
141 void ResetLineEnds();
142 /// Actions without undo
143 void BasicInsertString(int position
, const char *s
, int insertLength
);
144 void BasicDeleteChars(int position
, int deleteLength
);
151 /// Retrieving positions outside the range of the buffer works and returns 0
152 char CharAt(int position
) const;
153 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
) const;
154 char StyleAt(int position
) const;
155 void GetStyleRange(unsigned char *buffer
, int position
, int lengthRetrieve
) const;
156 const char *BufferPointer();
157 const char *RangePointer(int position
, int rangeLength
);
158 int GapPosition() const;
161 void Allocate(int newSize
);
162 int GetLineEndTypes() const { return utf8LineEnds
; }
163 void SetLineEndTypes(int utf8LineEnds_
);
164 bool ContainsLineEnd(const char *s
, int length
) const;
165 void SetPerLine(PerLine
*pl
);
167 int LineStart(int line
) const;
168 int LineFromPosition(int pos
) const { return lv
.LineFromPosition(pos
); }
169 void InsertLine(int line
, int position
, bool lineStart
);
170 void RemoveLine(int line
);
171 const char *InsertString(int position
, const char *s
, int insertLength
, bool &startSequence
);
173 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
174 /// @return true if the style of a character is changed.
175 bool SetStyleAt(int position
, char styleValue
);
176 bool SetStyleFor(int position
, int length
, char styleValue
);
178 const char *DeleteChars(int position
, int deleteLength
, bool &startSequence
);
180 bool IsReadOnly() const;
181 void SetReadOnly(bool set
);
183 /// The save point is a marker in the undo stack where the container has stated that
184 /// the buffer was saved. Undo and redo can move over the save point.
186 bool IsSavePoint() const;
188 void TentativeStart();
189 void TentativeCommit();
190 bool TentativeActive() const;
191 int TentativeSteps();
193 bool SetUndoCollection(bool collectUndo
);
194 bool IsCollectingUndo() const;
195 void BeginUndoAction();
196 void EndUndoAction();
197 void AddUndoAction(int token
, bool mayCoalesce
);
198 void DeleteUndoHistory();
200 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
201 /// called that many times. Similarly for redo.
202 bool CanUndo() const;
204 const Action
&GetUndoStep() const;
205 void PerformUndoStep();
206 bool CanRedo() const;
208 const Action
&GetRedoStep() const;
209 void PerformRedoStep();