Merge branch 'master' into fastColorization
diff --git a/CONTRIBUTING b/CONTRIBUTING
new file mode 100644
index 0000000..73ab161
--- /dev/null
+++ b/CONTRIBUTING
@@ -0,0 +1,11 @@
+# Contributing
+Pull requests are welcome, feel free to contribute if you have implemented something which might be useful for the general audience of this little piece of software. Apparently, it became kind of a community project now. :)
+
+Whem contributing, please follow the following guidelines. I will keep it updated as we bump into something which worth doing better.
+- Try to follow the same coding and naming conventions you find in the source already. I know that everyone has its own preference/taste in coding, but please keep the source consistent in style.
+- Please submit to the 'dev' branch first for testing, and it will be merged to 'main' if it seems to work fine. I would like try keep 'master' in a good working condition, as more and more people are using it.
+- Please send your submissions in small, well defined requests, i. e. do not accumulate many unrelated changes in one large pull request. Keep your submissions as small as possible, it will make everyone's life easier.
+- Avoid using ImGui internal since it would make the source fragile against internal changes in ImGui.
+- Try to keep the perormance high within the render function. Try to avoid doing anything which leads to memory allocations (like using temporary std::string, std::vector variables), or complex algorithm. If you really have to, try to amortise it between frames.
+
+Thank you. :)
diff --git a/README.md b/README.md
index 635a3c6..e44d8f1 100644
--- a/README.md
+++ b/README.md
@@ -5,13 +5,13 @@
 
 Demo project: https://github.com/BalazsJako/ColorTextEditorDemo
 
-This is my attempt to write a relatively simple widget which provides source code editing functionality with basic syntax highlighting.
+This started as my attempt to write a relatively simple widget which provides source code editing functionality with basic syntax highlighting. Now there are other contributors who provide valuable additions.
 
-While it relies on Omar Cornut's https://github.com/ocornut/imgui, it does not follow the "pure" one widget - one function approach. Since the editor has to maintain a relatively complex internal state, it did not seem to be practical to try and enforce fully immediate mode.
+While it relies on Omar Cornut's https://github.com/ocornut/imgui, it does not follow the "pure" one widget - one function approach. Since the editor has to maintain a relatively complex and large internal state, it did not seem to be practical to try and enforce fully immediate mode.
 
-The code is work in progress, please report if you find any issues.
+The code is (still) work in progress, please report if you find any issues.
 
-Main features are:
+# Main features
  - approximates typical code editor look and feel (essential mouse/keyboard commands work - I mean, the commands _I_ normally use :))
  - undo/redo support
  - extensible, multiple language syntax support
@@ -21,9 +21,11 @@
  - color palette support: you can switch between different color palettes, or even define your own
  - supports both fixed and variable-width fonts
  
-Known issues:
- - syntax highligthing is based on std::regex, which is diasppointingly slow. Because of that, the highlighting process is amortized between multiple frames. Hand-written colorizers and/or a lexical scanner might help resolve this problem.
- - 8 bit character only, no Unicode or Utf support (yet)
+# Known issues
+ - syntax highligthing is based on std::regex, which is diasppointingly slow. Because of that, the highlighting process is amortized between multiple frames. Hand-written colorizers and/or a generated lexical scanner might help resolve this problem.
+ - 8 bit character only, no Unicode or Utf support
  - there's no find/replace support
 
-Don't forget to post your screenshots if you use this little piece of software in order to keep me motivated. :)
+Don't forget to post your screenshots if you use this little piece of software in order to keep me us motivated. :)
+
+Thank you. :)
diff --git a/TextEditor.cpp b/TextEditor.cpp
index 39fa1ba..a989f72 100644
--- a/TextEditor.cpp
+++ b/TextEditor.cpp
@@ -872,10 +872,18 @@
 	{

 		InsertLine(coord.mLine + 1);

 		auto& line = mLines[coord.mLine];

-		auto& newLine = mLines[coord.mLine + 1];

-		newLine.insert(newLine.begin(), line.begin() + coord.mColumn, line.end());

+		auto& newLine = mLines[coord.mLine + 1];
+		
+		if (mLanguageDefinition.mAutoIndentation)
+		{

+			for (size_t it = 0; it < line.size() && isblank(line[it].mChar); ++it)

+				newLine.push_back(line[it]);
+		}
+		

+		const size_t whitespaceSize = newLine.size();

+		newLine.insert(newLine.end(), line.begin() + coord.mColumn, line.end());

 		line.erase(line.begin() + coord.mColumn, line.begin() + line.size());

-		SetCursorPosition(Coordinates(coord.mLine + 1, 0));

+		SetCursorPosition(Coordinates(coord.mLine + 1, (int)whitespaceSize));

 	}

 	else

 	{

@@ -2221,7 +2229,8 @@
 		langDef.mCommentStart = "/*";

 		langDef.mCommentEnd = "*/";

 

-		langDef.mCaseSensitive = true;

+		langDef.mCaseSensitive = true;
+		langDef.mAutoIndentation = true;

 

 		langDef.mName = "C++";

 

@@ -2292,7 +2301,8 @@
 		langDef.mCommentStart = "/*";

 		langDef.mCommentEnd = "*/";

 

-		langDef.mCaseSensitive = true;

+		langDef.mCaseSensitive = true;
+		langDef.mAutoIndentation = true;

 

 		langDef.mName = "HLSL";

 

@@ -2340,7 +2350,8 @@
 		langDef.mCommentStart = "/*";

 		langDef.mCommentEnd = "*/";

 

-		langDef.mCaseSensitive = true;

+		langDef.mCaseSensitive = true;
+		langDef.mAutoIndentation = true;

 

 		langDef.mName = "GLSL";

 

@@ -2408,7 +2419,8 @@
 		langDef.mCommentStart = "/*";

 		langDef.mCommentEnd = "*/";

 

-		langDef.mCaseSensitive = true;

+		langDef.mCaseSensitive = true;
+		langDef.mAutoIndentation = true;

 

 		langDef.mName = "C";

 

@@ -2471,7 +2483,8 @@
 		langDef.mCommentStart = "/*";

 		langDef.mCommentEnd = "*/";

 

-		langDef.mCaseSensitive = false;

+		langDef.mCaseSensitive = false;
+		langDef.mAutoIndentation = false;

 

 		langDef.mName = "SQL";

 

@@ -2520,7 +2533,8 @@
 		langDef.mCommentStart = "/*";

 		langDef.mCommentEnd = "*/";

 

-		langDef.mCaseSensitive = true;

+		langDef.mCaseSensitive = true;
+		langDef.mAutoIndentation = true;

 

 		langDef.mName = "AngelScript";

 

@@ -2573,7 +2587,8 @@
 		langDef.mCommentStart = "\\-\\-\\[\\[";

 		langDef.mCommentEnd = "\\]\\]";

 

-		langDef.mCaseSensitive = true;

+		langDef.mCaseSensitive = true;
+		langDef.mAutoIndentation = false;

 

 		langDef.mName = "Lua";

 

diff --git a/TextEditor.h b/TextEditor.h
index c0f7564..214d3b4 100644
--- a/TextEditor.h
+++ b/TextEditor.h
@@ -141,25 +141,25 @@
 	struct LanguageDefinition

 	{

 		typedef std::pair<std::string, PaletteIndex> TokenRegexString;

-		typedef std::vector<TokenRegexString> TokenRegexStrings;
+		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;
-		
+		std::string mCommentStart, mCommentEnd;

+		

 		TokenizeCallback mTokenize;

 

 		TokenRegexStrings mTokenRegexStrings;

 

-		bool mCaseSensitive;
-		
-		LanguageDefinition()
-			: mTokenize(nullptr)
-		{
-		}
+		bool mCaseSensitive;

+		

+		LanguageDefinition()

+			: mTokenize(nullptr)

+		{

+		}

 		

 		static const LanguageDefinition& CPlusPlus();

 		static const LanguageDefinition& HLSL();

@@ -317,7 +317,7 @@
 	bool mWithinRender;

 	bool mScrollToCursor;

 	bool mTextChanged;

-	int  mTextStart;                   // position (in pixels) where a code line starts relative to the left of the TextEditor.

+	float  mTextStart;                   // position (in pixels) where a code line starts relative to the left of the TextEditor.

 	int  mLeftMargin;

 	bool mCursorPositionChanged;

 	int mColorRangeMin, mColorRangeMax;

@@ -333,4 +333,3 @@
 	ImVec2 mCharAdvance;

 	Coordinates mInteractiveStart, mInteractiveEnd;

 };

-