Merge branch 'dev' of https://github.com/BalazsJako/ImGuiColorTextEdit into dev
diff --git a/TextEditor.cpp b/TextEditor.cpp
index 82717b7..4bf17b7 100644
--- a/TextEditor.cpp
+++ b/TextEditor.cpp
@@ -459,7 +459,10 @@
 	while (!isword || skip)

 	{

 		if (at.mLine >= mLines.size())

-			return Coordinates(std::max(0, (int)mLines.size() - 1), 0);

+		{

+			auto l = std::max(0, (int) mLines.size() - 1);

+			return Coordinates(l, GetLineMaxColumn(l));

+		}

 

 		auto& line = mLines[at.mLine];

 		if (cindex < (int)line.size())

@@ -479,10 +482,11 @@
 			cindex = 0;

 			++at.mLine;

 			skip = false;

+			isword = false;

 		}

 	}

 

-	return Coordinates(std::max(0, (int)mLines.size() - 1), 0);

+	return at;

 }

 

 int TextEditor::GetCharacterIndex(const Coordinates& aCoordinates) const

@@ -1455,6 +1459,11 @@
 		mCursorPositionChanged = true;

 }

 

+void TextEditor::SetTabSize(int aValue)

+{

+	mTabSize = std::max(0, std::min(32, aValue));

+}

+

 void TextEditor::InsertText(const std::string & aValue)

 {

 	InsertText(aValue.c_str());

@@ -1619,23 +1628,29 @@
 {

 	auto oldPos = mState.mCursorPosition;

 

-	if (mLines.empty())

+	if (mLines.empty() || oldPos.mLine >= mLines.size())

 		return;

 

+	auto cindex = GetCharacterIndex(mState.mCursorPosition);

 	while (aAmount-- > 0)

 	{

-		auto chars = GetLineMaxColumn(mState.mCursorPosition.mLine);

-		if (mState.mCursorPosition.mColumn >= chars)

+		auto lindex = mState.mCursorPosition.mLine;

+		auto& line = mLines[lindex];

+

+		if (cindex >= line.size())

 		{

 			if (mState.mCursorPosition.mLine < mLines.size() - 1)

 			{

 				mState.mCursorPosition.mLine = std::max(0, std::min((int)mLines.size() - 1, mState.mCursorPosition.mLine + 1));

 				mState.mCursorPosition.mColumn = 0;

 			}

+			else

+				return;

 		}

 		else

 		{

-			mState.mCursorPosition.mColumn = std::max(0, std::min(chars, mState.mCursorPosition.mColumn + 1));

+			cindex += UTF8CharLength(line[cindex].mChar);

+			mState.mCursorPosition = Coordinates(lindex, GetCharacterColumn(lindex, cindex));

 			if (aWordMode)

 				mState.mCursorPosition = FindNextWord(mState.mCursorPosition);

 		}

diff --git a/TextEditor.h b/TextEditor.h
index 2661909..65436de 100644
--- a/TextEditor.h
+++ b/TextEditor.h
@@ -196,9 +196,11 @@
 

 	void Render(const char* aTitle, const ImVec2& aSize = ImVec2(), bool aBorder = false);

 	void SetText(const std::string& aText);

-	void SetTextLines(const std::vector<std::string>& aLines);

 	std::string GetText() const;

+

+	void SetTextLines(const std::vector<std::string>& aLines);

 	std::vector<std::string> GetTextLines() const;

+

 	std::string GetSelectedText() const;

 	std::string GetCurrentLineText()const;

 

@@ -228,6 +230,9 @@
 	inline void SetShowWhitespaces(bool aValue) { mShowWhitespaces = aValue; }

 	inline bool IsShowingWhitespaces() const { return mShowWhitespaces; }

 

+	void SetTabSize(int aValue);

+	inline int GetTabSize() const { return mTabSize; }

+

 	void InsertText(const std::string& aValue);

 	void InsertText(const char* aValue);

 

@@ -357,7 +362,7 @@
 	bool mScrollToTop;

 	bool mTextChanged;

 	bool mColorizerEnabled;

-	float  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;