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(Sci::Line line
)=0;
21 virtual void RemoveLine(Sci::Line line
)=0;
25 * The line vector contains information about each of the lines in a cell buffer.
35 // Deleted so LineVector objects can not be copied.
36 LineVector(const LineVector
&) = delete;
37 void operator=(const LineVector
&) = delete;
40 void SetPerLine(PerLine
*pl
);
42 void InsertText(Sci::Line line
, Sci::Position delta
);
43 void InsertLine(Sci::Line line
, Sci::Position position
, bool lineStart
);
44 void SetLineStart(Sci::Line line
, Sci::Position position
);
45 void RemoveLine(Sci::Line line
);
46 Sci::Line
Lines() const {
47 return starts
.Partitions();
49 Sci::Line
LineFromPosition(Sci::Position pos
) const;
50 Sci::Position
LineStart(Sci::Line line
) const {
51 return starts
.PositionFromPartition(line
);
55 enum actionType
{ insertAction
, removeAction
, startAction
, containerAction
};
58 * Actions are used to store all the information required to perform one undo/redo step.
63 Sci::Position position
;
64 std::unique_ptr
<char[]> data
;
65 Sci::Position lenData
;
69 // Deleted so Action objects can not be copied.
70 Action(const Action
&other
) = delete;
71 Action
&operator=(const Action
&other
) = delete;
72 Action
&operator=(const Action
&&other
) = delete;
73 // Move constructor allows vector to be resized without reallocating.
74 // Could use =default but MSVC 2013 warns.
75 Action(Action
&&other
);
77 void Create(actionType at_
, Sci::Position position_
=0, const char *data_
=0, Sci::Position lenData_
=0, bool mayCoalesce_
=true);
85 std::vector
<Action
> actions
;
88 int undoSequenceDepth
;
92 void EnsureUndoRoom();
96 // Deleted so UndoHistory objects can not be copied.
97 UndoHistory(const UndoHistory
&) = delete;
98 void operator=(const UndoHistory
&) = delete;
101 const char *AppendAction(actionType at
, Sci::Position position
, const char *data
, Sci::Position lengthData
, bool &startSequence
, bool mayCoalesce
=true);
103 void BeginUndoAction();
104 void EndUndoAction();
105 void DropUndoSequence();
106 void DeleteUndoHistory();
108 /// The save point is a marker in the undo stack where the container has stated that
109 /// the buffer was saved. Undo and redo can move over the save point.
111 bool IsSavePoint() const;
113 // Tentative actions are used for input composition so that it can be undone cleanly
114 void TentativeStart();
115 void TentativeCommit();
116 bool TentativeActive() const { return tentativePoint
>= 0; }
117 int TentativeSteps();
119 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
120 /// called that many times. Similarly for redo.
121 bool CanUndo() const;
123 const Action
&GetUndoStep() const;
124 void CompletedUndoStep();
125 bool CanRedo() const;
127 const Action
&GetRedoStep() const;
128 void CompletedRedoStep();
132 * Holder for an expandable array of characters that supports undo and line markers.
133 * Based on article "Data Structures in a Bit-Mapped Text Editor"
134 * by Wilfred J. Hansen, Byte January 1987, page 183.
138 SplitVector
<char> substance
;
139 SplitVector
<char> style
;
148 bool UTF8LineEndOverlaps(Sci::Position position
) const;
149 void ResetLineEnds();
150 /// Actions without undo
151 void BasicInsertString(Sci::Position position
, const char *s
, Sci::Position insertLength
);
152 void BasicDeleteChars(Sci::Position position
, Sci::Position deleteLength
);
157 // Deleted so CellBuffer objects can not be copied.
158 CellBuffer(const CellBuffer
&) = delete;
159 void operator=(const CellBuffer
&) = delete;
162 /// Retrieving positions outside the range of the buffer works and returns 0
163 char CharAt(Sci::Position position
) const;
164 void GetCharRange(char *buffer
, Sci::Position position
, Sci::Position lengthRetrieve
) const;
165 char StyleAt(Sci::Position position
) const;
166 void GetStyleRange(unsigned char *buffer
, Sci::Position position
, Sci::Position lengthRetrieve
) const;
167 const char *BufferPointer();
168 const char *RangePointer(Sci::Position position
, Sci::Position rangeLength
);
169 Sci::Position
GapPosition() const;
171 Sci::Position
Length() const;
172 void Allocate(Sci::Position newSize
);
173 int GetLineEndTypes() const { return utf8LineEnds
; }
174 void SetLineEndTypes(int utf8LineEnds_
);
175 bool ContainsLineEnd(const char *s
, Sci::Position length
) const;
176 void SetPerLine(PerLine
*pl
);
177 Sci::Line
Lines() const;
178 Sci::Position
LineStart(Sci::Line line
) const;
179 Sci::Line
LineFromPosition(Sci::Position pos
) const { return lv
.LineFromPosition(pos
); }
180 void InsertLine(Sci::Line line
, Sci::Position position
, bool lineStart
);
181 void RemoveLine(Sci::Line line
);
182 const char *InsertString(Sci::Position position
, const char *s
, Sci::Position insertLength
, bool &startSequence
);
184 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
185 /// @return true if the style of a character is changed.
186 bool SetStyleAt(Sci::Position position
, char styleValue
);
187 bool SetStyleFor(Sci::Position position
, Sci::Position lengthStyle
, char styleValue
);
189 const char *DeleteChars(Sci::Position position
, Sci::Position deleteLength
, bool &startSequence
);
191 bool IsReadOnly() const;
192 void SetReadOnly(bool set
);
194 /// The save point is a marker in the undo stack where the container has stated that
195 /// the buffer was saved. Undo and redo can move over the save point.
197 bool IsSavePoint() const;
199 void TentativeStart();
200 void TentativeCommit();
201 bool TentativeActive() const;
202 int TentativeSteps();
204 bool SetUndoCollection(bool collectUndo
);
205 bool IsCollectingUndo() const;
206 void BeginUndoAction();
207 void EndUndoAction();
208 void AddUndoAction(Sci::Position token
, bool mayCoalesce
);
209 void DeleteUndoHistory();
211 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
212 /// called that many times. Similarly for redo.
213 bool CanUndo() const;
215 const Action
&GetUndoStep() const;
216 void PerformUndoStep();
217 bool CanRedo() const;
219 const Action
&GetRedoStep() const;
220 void PerformRedoStep();