Adding a guard to ensure the static buffer string is empty when entering the method.
diff --git a/TextEditor.cpp b/TextEditor.cpp
index e19493a..818ca4e 100644
--- a/TextEditor.cpp
+++ b/TextEditor.cpp
@@ -33,7 +33,7 @@
 	, mOverwrite(false)

 	, mReadOnly(false)

 	, mWithinRender(false)

-	, mScrollToCursor(false)
+	, mScrollToCursor(false)

 	, mScrollToTop(false)

 	, mTextChanged(false)

 	, mTextStart(20.0f)

@@ -514,8 +514,8 @@
 		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);
-		else if (!IsReadOnly() && !ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Tab)))
+			EnterCharacter('\n', false);

+		else if (!IsReadOnly() && !ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Tab)))

 			EnterCharacter('\t', shift);

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

 		{

@@ -616,24 +616,26 @@
 	/* 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);
-	}
+

+	/* 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;

+	assert(buffer.empty());

+	

 	auto contentSize = ImGui::GetWindowContentRegionMax();

 	auto drawList = ImGui::GetWindowDrawList();

-	float longest(mTextStart);
-	
-	if (mScrollToTop)
-	{
-		mScrollToTop = false;
-		ImGui::SetScrollY(0.f);
+	float longest(mTextStart);

+	

+	if (mScrollToTop)

+	{

+		mScrollToTop = false;

+		ImGui::SetScrollY(0.f);

 	}

 

 	ImVec2 cursorScreenPos = ImGui::GetCursorScreenPos();

@@ -864,12 +866,12 @@
 		{

 			mLines.back().emplace_back(Glyph(chr, PaletteIndex::Default));

 		}

-	}
-	
-	mTextChanged = true;
+	}

+	

+	mTextChanged = true;

 	mScrollToTop = true;

 

-	mUndoBuffer.clear();
+	mUndoBuffer.clear();

 	mUndoIndex = 0;

 

 	Colorize();

@@ -897,10 +899,10 @@
 		}

 	}

 

-	mTextChanged = true;
+	mTextChanged = true;

 	mScrollToTop = true;

 

-	mUndoBuffer.clear();
+	mUndoBuffer.clear();

 	mUndoIndex = 0;

 

 	Colorize();

@@ -942,25 +944,25 @@
 				auto& line = mLines[i];

 				if (aShift)

 				{

-					if (line.empty() == false)
-					{
-						if (line.front().mChar == '\t')
-						{
-							line.erase(line.begin());
-							if (i == end.mLine && end.mColumn > 0)
-								end.mColumn--;
-							modified = true;
-						}
-					}
-					else
-					{
-						for (int j = 0; j < mTabSize && line.empty() == false && line.front().mChar == ' '; j++)
-						{
-							line.erase(line.begin());
-							if (i == end.mLine && end.mColumn > 0)
-								end.mColumn--;
-							modified = true;
-						}
+					if (line.empty() == false)

+					{

+						if (line.front().mChar == '\t')

+						{

+							line.erase(line.begin());

+							if (i == end.mLine && end.mColumn > 0)

+								end.mColumn--;

+							modified = true;

+						}

+					}

+					else

+					{

+						for (int j = 0; j < mTabSize && line.empty() == false && line.front().mChar == ' '; j++)

+						{

+							line.erase(line.begin());

+							if (i == end.mLine && end.mColumn > 0)

+								end.mColumn--;

+							modified = true;

+						}

 					}

 				}

 				else

@@ -1604,7 +1606,7 @@
 

 const TextEditor::Palette & TextEditor::GetDarkPalette()

 {

-	static Palette p = { {

+	const static Palette p = { {

 		0xff7f7f7f,	// Default

 		0xffd69c56,	// Keyword	

 		0xff00ff00,	// Number

@@ -1632,7 +1634,7 @@
 

 const TextEditor::Palette & TextEditor::GetLightPalette()

 {

-	static Palette p = { {

+	const static Palette p = { {

 		0xff7f7f7f,	// None

 		0xffff0c06,	// Keyword	

 		0xff008000,	// Number

@@ -1660,7 +1662,7 @@
 

 const TextEditor::Palette & TextEditor::GetRetroBluePalette()

 {

-	static Palette p = { {

+	const static Palette p = { {

 		0xff00ffff,	// None

 		0xffffff00,	// Keyword	

 		0xff00ff00,	// Number