Преглед на файлове

Fixed index calculations in slice text node

CPKreuz преди 2 седмици
родител
ревизия
a9b990272d
променени са 1 файла, в които са добавени 6 реда и са изтрити 3 реда
  1. 6 3
      src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/SliceTextNode.cs

+ 6 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/SliceTextNode.cs

@@ -27,9 +27,12 @@ public class SliceTextNode : Node
 
     protected override void OnExecute(RenderContext context)
     {
-        SlicedText.Value = Text.Value.Substring(
-            Math.Min(Index.Value, Text.Value.Length - 1),
-            Math.Min(Length.Value, Text.Value.Length));
+        var textLength = Text.Value.Length;
+
+        var startIndex = Math.Clamp(Index.Value, 0, textLength);
+        var length = Math.Clamp(Length.Value, 0, textLength - startIndex);
+        
+        SlicedText.Value = Text.Value.Substring(startIndex, length);
     }
 
     public override Node CreateCopy() =>