CPKreuz 2 дней назад
Родитель
Сommit
f4c6b31398

+ 8 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/SliceTextNode.cs

@@ -9,7 +9,7 @@ public class SliceTextNode : Node
     
     public InputProperty<bool> UseLength { get; }
     
-    public InputProperty<string> Text { get; }
+    public InputProperty<string?> Text { get; }
     
     public InputProperty<int> Index { get; }
     
@@ -31,6 +31,13 @@ public class SliceTextNode : Node
     protected override void OnExecute(RenderContext context)
     {
         var text = Text.Value;
+
+        if (text == null)
+        {
+            SlicedText.Value = string.Empty;
+            return;
+        }
+
         var startIndex = Math.Clamp(Index.Value, 0, text.Length);
 
         if (!UseLength.Value)

+ 10 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/TextIndexOfNode.cs

@@ -11,9 +11,9 @@ public class TextIndexOfNode : Node
     
     public InputProperty<bool> MatchCase { get; }
     
-    public InputProperty<string> Text { get; }
+    public InputProperty<string?> Text { get; }
     
-    public InputProperty<string> SearchText { get; }
+    public InputProperty<string?> SearchText { get; }
 
     public TextIndexOfNode()
     {
@@ -34,6 +34,14 @@ public class TextIndexOfNode : Node
         var text = Text.Value;
         var searchText = SearchText.Value;
 
+        if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(searchText))
+        {
+            FirstIndex.Value = -1;
+            LastIndex.Value = -1;
+            
+            return;
+        }
+
         FirstIndex.Value = text.IndexOf(searchText, comparisonMode);
         LastIndex.Value = text.LastIndexOf(searchText, comparisonMode);
     }

+ 7 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/TextInfoNode.cs

@@ -22,6 +22,13 @@ public class TextInfoNode : Node
     protected override void OnExecute(RenderContext context)
     {
         var text = Text.Value;
+
+        if (string.IsNullOrEmpty(text))
+        {
+            Length.Value = 0;
+            LineCount.Value = 0;
+            return;
+        }
         
         Length.Value = text.Length;
         LineCount.Value = text.AsSpan().Count('\n');