16 enum class PaletteIndex
37 CurrentLineFillInactive,
42 enum class SelectionMode
53 std::string mCondition;
71 Coordinates() : mLine(0), mColumn(0) {}
72 Coordinates(
int aLine,
int aColumn) : mLine(aLine), mColumn(aColumn)
77 static Coordinates Invalid() {
static Coordinates invalid(-1, -1);
return invalid; }
79 bool operator ==(
const Coordinates& o)
const
86 bool operator !=(
const Coordinates& o)
const
93 bool operator <(
const Coordinates& o)
const
96 return mLine < o.mLine;
97 return mColumn < o.mColumn;
100 bool operator >(
const Coordinates& o)
const
102 if (mLine != o.mLine)
103 return mLine > o.mLine;
104 return mColumn > o.mColumn;
107 bool operator <=(
const Coordinates& o)
const
109 if (mLine != o.mLine)
110 return mLine < o.mLine;
111 return mColumn <= o.mColumn;
114 bool operator >=(
const Coordinates& o)
const
116 if (mLine != o.mLine)
117 return mLine > o.mLine;
118 return mColumn >= o.mColumn;
125 std::string mDeclaration;
128 typedef std::string String;
129 typedef std::unordered_map<std::string, Identifier> Identifiers;
130 typedef std::unordered_set<std::string> Keywords;
131 typedef std::map<int, std::string> ErrorMarkers;
132 typedef std::unordered_set<int> Breakpoints;
133 typedef std::array<ImU32, (unsigned)PaletteIndex::Max> Palette;
134 typedef uint8_t Char;
139 PaletteIndex mColorIndex = PaletteIndex::Default;
141 bool mMultiLineComment : 1;
142 bool mPreprocessor : 1;
144 Glyph(Char aChar, PaletteIndex aColorIndex) : mChar(aChar), mColorIndex(aColorIndex),
145 mComment(
false), mMultiLineComment(
false), mPreprocessor(
false) {}
148 typedef std::vector<Glyph> Line;
149 typedef std::vector<Line> Lines;
151 struct LanguageDefinition
153 typedef std::pair<std::string, PaletteIndex> TokenRegexString;
154 typedef std::vector<TokenRegexString> TokenRegexStrings;
155 typedef bool(*TokenizeCallback)(
const char * in_begin,
const char * in_end,
const char *& out_begin,
const char *& out_end, PaletteIndex & paletteIndex);
159 Identifiers mIdentifiers;
160 Identifiers mPreprocIdentifiers;
161 std::string mCommentStart, mCommentEnd, mSingleLineComment;
163 bool mAutoIndentation;
165 TokenizeCallback mTokenize;
167 TokenRegexStrings mTokenRegexStrings;
172 : mPreprocChar(
'#'), mAutoIndentation(
true), mTokenize(
nullptr), mCaseSensitive(
true)
176 static const LanguageDefinition& CPlusPlus();
177 static const LanguageDefinition& HLSL();
178 static const LanguageDefinition& GLSL();
179 static const LanguageDefinition& C();
180 static const LanguageDefinition& SQL();
181 static const LanguageDefinition& AngelScript();
182 static const LanguageDefinition& Lua();
189 const LanguageDefinition& GetLanguageDefinition()
const {
return mLanguageDefinition; }
191 const Palette& GetPalette()
const {
return mPaletteBase; }
192 void SetPalette(
const Palette& aValue);
194 void SetErrorMarkers(
const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; }
195 void SetBreakpoints(
const Breakpoints& aMarkers) { mBreakpoints = aMarkers; }
197 void Render(
const char* aTitle,
const ImVec2& aSize = ImVec2(),
bool aBorder =
false);
198 void SetText(
const std::string& aText);
199 std::string GetText()
const;
201 void SetTextLines(
const std::vector<std::string>& aLines);
202 std::vector<std::string> GetTextLines()
const;
204 std::string GetSelectedText()
const;
205 std::string GetCurrentLineText()
const;
207 int GetTotalLines()
const {
return (
int)mLines.size(); }
208 bool IsOverwrite()
const {
return mOverwrite; }
210 void SetReadOnly(
bool aValue);
211 bool IsReadOnly()
const {
return mReadOnly; }
212 bool IsTextChanged()
const {
return mTextChanged; }
213 bool IsCursorPositionChanged()
const {
return mCursorPositionChanged; }
215 bool IsColorizerEnabled()
const {
return mColorizerEnabled; }
216 void SetColorizerEnable(
bool aValue);
218 Coordinates GetCursorPosition()
const {
return GetActualCursorCoordinates(); }
219 void SetCursorPosition(
const Coordinates& aPosition);
221 inline void SetHandleMouseInputs (
bool aValue){ mHandleMouseInputs = aValue;}
222 inline bool IsHandleMouseInputsEnabled()
const {
return mHandleKeyboardInputs; }
224 inline void SetHandleKeyboardInputs (
bool aValue){ mHandleKeyboardInputs = aValue;}
225 inline bool IsHandleKeyboardInputsEnabled()
const {
return mHandleKeyboardInputs; }
227 inline void SetImGuiChildIgnored (
bool aValue){ mIgnoreImGuiChild = aValue;}
228 inline bool IsImGuiChildIgnored()
const {
return mIgnoreImGuiChild; }
230 inline void SetShowWhitespaces(
bool aValue) { mShowWhitespaces = aValue; }
231 inline bool IsShowingWhitespaces()
const {
return mShowWhitespaces; }
233 void SetTabSize(
int aValue);
234 inline int GetTabSize()
const {
return mTabSize; }
236 void InsertText(
const std::string& aValue);
237 void InsertText(
const char* aValue);
239 void MoveUp(
int aAmount = 1,
bool aSelect =
false);
240 void MoveDown(
int aAmount = 1,
bool aSelect =
false);
241 void MoveLeft(
int aAmount = 1,
bool aSelect =
false,
bool aWordMode =
false);
242 void MoveRight(
int aAmount = 1,
bool aSelect =
false,
bool aWordMode =
false);
243 void MoveTop(
bool aSelect =
false);
244 void MoveBottom(
bool aSelect =
false);
245 void MoveHome(
bool aSelect =
false);
246 void MoveEnd(
bool aSelect =
false);
248 void SetSelectionStart(
const Coordinates& aPosition);
249 void SetSelectionEnd(
const Coordinates& aPosition);
250 void SetSelection(
const Coordinates& aStart,
const Coordinates& aEnd, SelectionMode aMode = SelectionMode::Normal);
251 void SelectWordUnderCursor();
253 bool HasSelection()
const;
260 bool CanUndo()
const;
261 bool CanRedo()
const;
262 void Undo(
int aSteps = 1);
263 void Redo(
int aSteps = 1);
265 static const Palette& GetDarkPalette();
266 static const Palette& GetLightPalette();
267 static const Palette& GetRetroBluePalette();
270 typedef std::vector<std::pair<std::regex, PaletteIndex>> RegexList;
274 Coordinates mSelectionStart;
275 Coordinates mSelectionEnd;
276 Coordinates mCursorPosition;
286 const std::string& aAdded,
287 const TextEditor::Coordinates aAddedStart,
288 const TextEditor::Coordinates aAddedEnd,
290 const std::string& aRemoved,
291 const TextEditor::Coordinates aRemovedStart,
292 const TextEditor::Coordinates aRemovedEnd,
294 TextEditor::EditorState& aBefore,
295 TextEditor::EditorState& aAfter);
297 void Undo(TextEditor* aEditor);
298 void Redo(TextEditor* aEditor);
301 Coordinates mAddedStart;
302 Coordinates mAddedEnd;
304 std::string mRemoved;
305 Coordinates mRemovedStart;
306 Coordinates mRemovedEnd;
312 typedef std::vector<UndoRecord> UndoBuffer;
314 void ProcessInputs();
315 void Colorize(
int aFromLine = 0,
int aCount = -1);
316 void ColorizeRange(
int aFromLine = 0,
int aToLine = 0);
317 void ColorizeInternal();
318 float TextDistanceToLineStart(
const Coordinates& aFrom)
const;
319 void EnsureCursorVisible();
320 int GetPageSize()
const;
326 int InsertTextAt(
Coordinates& aWhere,
const char* aValue);
327 void AddUndo(UndoRecord& aValue);
328 Coordinates ScreenPosToCoordinates(
const ImVec2& aPosition)
const;
332 int GetCharacterIndex(
const Coordinates& aCoordinates)
const;
333 int GetCharacterColumn(
int aLine,
int aIndex)
const;
334 int GetLineCharacterCount(
int aLine)
const;
335 int GetLineMaxColumn(
int aLine)
const;
336 bool IsOnWordBoundary(
const Coordinates& aAt)
const;
337 void RemoveLine(
int aStart,
int aEnd);
338 void RemoveLine(
int aIndex);
339 Line& InsertLine(
int aIndex);
340 void EnterCharacter(ImWchar aChar,
bool aShift);
342 void DeleteSelection();
343 std::string GetWordUnderCursor()
const;
344 std::string GetWordAt(
const Coordinates& aCoords)
const;
345 ImU32 GetGlyphColor(
const Glyph& aGlyph)
const;
347 void HandleKeyboardInputs();
348 void HandleMouseInputs();
354 UndoBuffer mUndoBuffer;
361 bool mScrollToCursor;
364 bool mColorizerEnabled;
367 bool mCursorPositionChanged;
368 int mColorRangeMin, mColorRangeMax;
369 SelectionMode mSelectionMode;
370 bool mHandleKeyboardInputs;
371 bool mHandleMouseInputs;
372 bool mIgnoreImGuiChild;
373 bool mShowWhitespaces;
375 Palette mPaletteBase;
378 RegexList mRegexList;
381 Breakpoints mBreakpoints;
382 ErrorMarkers mErrorMarkers;
385 std::string mLineBuffer;
Definition TextEditor.h:50
Definition TextEditor.h:69
Definition TextEditor.h:137
Definition TextEditor.h:123
Definition TextEditor.h:152