From 8ba66f664bf8fa1003b27cd92d3821fca455805f Mon Sep 17 00:00:00 2001 From: Chernyavsky Andrey Date: Sat, 17 May 2025 11:47:45 +0500 Subject: [PATCH] Fix: Remove `\n` for last fragment in `CopyText()` --- BeefLibs/Beefy2D/src/widgets/EditWidget.bf | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf index 18e5d0e1..17d88382 100644 --- a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf +++ b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf @@ -2376,7 +2376,10 @@ namespace Beefy.widgets // ... ExtractString(selection.mStartPos, selection.Length, cursorText); - cursorText.Append('\n'); + + // Skip new line for last fragment + if (@cursor.Index+1 < mTextCursors.Count) + cursorText.Append('\n'); text.Append(cursorText); extra.AppendF("{0}:{1};", cursorExtra, cursorText.Length); @@ -2556,8 +2559,6 @@ namespace Beefy.widgets { if ((cursorExtra.Length == 0) || (HasSelection())) { - /*if ((cursorExtra.Length == 0) && (cursorText[cursorText.Length-1] == '\n')) - cursorText.RemoveFromEnd(1);*/ PasteText(cursorText); } else// if (fragment.mExtra == "line") @@ -2602,8 +2603,6 @@ namespace Beefy.widgets { var fragment = fragments[idx]; var length = fragment.mText.Length; - if (idx + 1 == fragments.Count) - length--; PasteFragment(scope String(fragment.mText, 0, length), ""); if (idx + 1 < fragments.Count) @@ -2653,7 +2652,9 @@ namespace Beefy.widgets var fragment = fragments[idx--]; String cursorText = scope String(fragment.mText, 0, fragment.mText.Length); - cursorText.RemoveFromEnd(1); + + if (@cursor.Index+1 < sortedCursors.Count) + cursorText.RemoveFromEnd(1); mData.mUndoManager.Add(new SetCursorAction(this)); PasteFragment(cursorText, fragment.mExtra);