Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 47 additions & 51 deletions TextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class TextEditor

struct Breakpoint
{
int mLine;
bool mEnabled;
std::string mCondition;

Breakpoint()
: mLine(-1)
, mEnabled(false)
{}

bool mEnabled;
int mLine;
std::string mCondition;
};

// Represents a character coordinate from the user's point of view,
Expand All @@ -67,7 +67,6 @@ class TextEditor
// because it is rendered as " ABC" on the screen.
struct Coordinates
{
int mLine, mColumn;
Coordinates() : mLine(0), mColumn(0) {}
Coordinates(int aLine, int aColumn) : mLine(aLine), mColumn(aColumn)
{
Expand Down Expand Up @@ -117,6 +116,9 @@ class TextEditor
return mLine > o.mLine;
return mColumn >= o.mColumn;
}


int mLine, mColumn;
};

struct Identifier
Expand All @@ -135,8 +137,8 @@ class TextEditor

struct Glyph
{
Char mChar;
PaletteIndex mColorIndex = PaletteIndex::Default;
Char mChar;
bool mComment : 1;
bool mMultiLineComment : 1;
bool mPreprocessor : 1;
Expand All @@ -152,21 +154,7 @@ class TextEditor
{
typedef std::pair<std::string, PaletteIndex> TokenRegexString;
typedef std::vector<TokenRegexString> TokenRegexStrings;
typedef bool(*TokenizeCallback)(const char * in_begin, const char * in_end, const char *& out_begin, const char *& out_end, PaletteIndex & paletteIndex);

std::string mName;
Keywords mKeywords;
Identifiers mIdentifiers;
Identifiers mPreprocIdentifiers;
std::string mCommentStart, mCommentEnd, mSingleLineComment;
char mPreprocChar;
bool mAutoIndentation;

TokenizeCallback mTokenize;

TokenRegexStrings mTokenRegexStrings;

bool mCaseSensitive;
typedef bool(*TokenizeCallback)(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex);

LanguageDefinition()
: mPreprocChar('#'), mAutoIndentation(true), mTokenize(nullptr), mCaseSensitive(true)
Expand All @@ -180,6 +168,18 @@ class TextEditor
static const LanguageDefinition& SQL();
static const LanguageDefinition& AngelScript();
static const LanguageDefinition& Lua();


bool mCaseSensitive;
bool mAutoIndentation;
char mPreprocChar;
TokenizeCallback mTokenize;
Keywords mKeywords;
TokenRegexStrings mTokenRegexStrings;
Identifiers mIdentifiers;
Identifiers mPreprocIdentifiers;
std::string mName;
std::string mCommentStart, mCommentEnd, mSingleLineComment;
};

TextEditor();
Expand Down Expand Up @@ -218,13 +218,13 @@ class TextEditor
Coordinates GetCursorPosition() const { return GetActualCursorCoordinates(); }
void SetCursorPosition(const Coordinates& aPosition);

inline void SetHandleMouseInputs (bool aValue){ mHandleMouseInputs = aValue;}
inline void SetHandleMouseInputs(bool aValue) { mHandleMouseInputs = aValue; }
inline bool IsHandleMouseInputsEnabled() const { return mHandleKeyboardInputs; }

inline void SetHandleKeyboardInputs (bool aValue){ mHandleKeyboardInputs = aValue;}
inline void SetHandleKeyboardInputs(bool aValue) { mHandleKeyboardInputs = aValue; }
inline bool IsHandleKeyboardInputsEnabled() const { return mHandleKeyboardInputs; }

inline void SetImGuiChildIgnored (bool aValue){ mIgnoreImGuiChild = aValue;}
inline void SetImGuiChildIgnored(bool aValue) { mIgnoreImGuiChild = aValue; }
inline bool IsImGuiChildIgnored() const { return mIgnoreImGuiChild; }

inline void SetShowWhitespaces(bool aValue) { mShowWhitespaces = aValue; }
Expand Down Expand Up @@ -297,16 +297,15 @@ class TextEditor
void Undo(TextEditor* aEditor);
void Redo(TextEditor* aEditor);

std::string mAdded;

Coordinates mAddedStart;
Coordinates mAddedEnd;

std::string mRemoved;
Coordinates mRemovedStart;
Coordinates mRemovedEnd;

EditorState mBefore;
EditorState mAfter;
std::string mAdded;
std::string mRemoved;
};

typedef std::vector<UndoRecord> UndoBuffer;
Expand Down Expand Up @@ -348,42 +347,39 @@ class TextEditor
void HandleMouseInputs();
void Render();

float mLineSpacing;
Lines mLines;
EditorState mState;
UndoBuffer mUndoBuffer;
int mUndoIndex;

int mTabSize;
private:
bool mOverwrite;
bool mReadOnly;
bool mWithinRender;
bool mScrollToCursor;
bool mScrollToTop;
bool mTextChanged;
bool mColorizerEnabled;
float mTextStart; // position (in pixels) where a code line starts relative to the left of the TextEditor.
int mLeftMargin;
bool mCursorPositionChanged;
int mColorRangeMin, mColorRangeMax;
SelectionMode mSelectionMode;
bool mHandleKeyboardInputs;
bool mHandleMouseInputs;
bool mIgnoreImGuiChild;
bool mShowWhitespaces;

Palette mPaletteBase;
Palette mPalette;
LanguageDefinition mLanguageDefinition;
RegexList mRegexList;

bool mCursorPositionChanged;
bool mCheckComments;
Breakpoints mBreakpoints;
ErrorMarkers mErrorMarkers;
int mLeftMargin;
int mColorRangeMin, mColorRangeMax;
int mUndoIndex;
int mTabSize;
SelectionMode mSelectionMode;
float mTextStart; // position (in pixels) where a code line starts relative to the left of the TextEditor.
float mLineSpacing;
float mLastClick;
uint64_t mStartTime;
ImVec2 mCharAdvance;
Coordinates mInteractiveStart, mInteractiveEnd;
EditorState mState;
ErrorMarkers mErrorMarkers;
Lines mLines;
RegexList mRegexList;
UndoBuffer mUndoBuffer;
std::string mLineBuffer;
uint64_t mStartTime;

float mLastClick;
Breakpoints mBreakpoints;
Palette mPaletteBase;
Palette mPalette;
LanguageDefinition mLanguageDefinition;
};