Merge pull request #58 from marcel303/scrollFixOnSetText

Fix for not resetting the scroll position back to the top when SetText or SetTextLines is called.
diff --git a/TextEditor.cpp b/TextEditor.cpp
index d8a2acd..277344c 100644
--- a/TextEditor.cpp
+++ b/TextEditor.cpp
@@ -63,7 +63,7 @@
 

 void TextEditor::SetPalette(const Palette & aValue)

 {

-	mPalette = aValue;

+	mPaletteBase = aValue;

 }

 

 int TextEditor::AppendBuffer(std::string& aBuffer, char chr, int aIndex)

@@ -514,7 +514,9 @@
 		else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_A)))

 			SelectAll();

 		else if (!IsReadOnly() && !ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)))

-			EnterCharacter('\n', false);

+			EnterCharacter('\n', false);
+		else if (!IsReadOnly() && !ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Tab)))
+			EnterCharacter('\t', shift);

 		else if (!IsReadOnly() && !ctrl && !alt)

 		{

 			for (size_t i = 0; i < sizeof(io.InputCharacters) / sizeof(io.InputCharacters[0]); i++)

@@ -614,7 +616,15 @@
 	/* Compute mCharAdvance regarding to scaled font size (Ctrl + mouse wheel)*/

 	const float fontSize = ImGui::CalcTextSize("#").x;

 	mCharAdvance = ImVec2(fontSize, ImGui::GetTextLineHeightWithSpacing() * mLineSpacing);

-

+
+	/* Update palette with the current alpha from style */
+	for (int i = 0; i < (int)PaletteIndex::Max; ++i)
+	{
+		auto color = ImGui::ColorConvertU32ToFloat4(mPaletteBase[i]);
+		color.w *= ImGui::GetStyle().Alpha;
+		mPalette[i] = ImGui::ColorConvertFloat4ToU32(color);
+	}
+	

 	static std::string buffer;

 	auto contentSize = ImGui::GetWindowContentRegionMax();

 	auto drawList = ImGui::GetWindowDrawList();

@@ -859,7 +869,8 @@
 	mTextChanged = true;
 	mScrollToTop = true;

 

-	mUndoBuffer.clear();

+	mUndoBuffer.clear();
+	mUndoIndex = 0;

 

 	Colorize();

 }

@@ -889,7 +900,8 @@
 	mTextChanged = true;
 	mScrollToTop = true;

 

-	mUndoBuffer.clear();

+	mUndoBuffer.clear();
+	mUndoIndex = 0;

 

 	Colorize();

 }

diff --git a/TextEditor.h b/TextEditor.h
index 3ca3813..0f32ed9 100644
--- a/TextEditor.h
+++ b/TextEditor.h
@@ -181,7 +181,7 @@
 	void SetLanguageDefinition(const LanguageDefinition& aLanguageDef);

 	const LanguageDefinition& GetLanguageDefinition() const { return mLanguageDefinition; }

 

-	const Palette& GetPalette() const { return mPalette; }

+	const Palette& GetPalette() const { return mPaletteBase; }

 	void SetPalette(const Palette& aValue);

 

 	void SetErrorMarkers(const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; }

@@ -335,7 +335,8 @@
 	bool mCursorPositionChanged;

 	int mColorRangeMin, mColorRangeMax;

 	SelectionMode mSelectionMode;

-

+
+	Palette mPaletteBase;

 	Palette mPalette;

 	LanguageDefinition mLanguageDefinition;

 	RegexList mRegexList;