Bläddra i källkod

Added character position node

CPKreuz 2 veckor sedan
förälder
incheckning
d37dcd1ae0

+ 43 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/TextIndexOfNode.cs

@@ -0,0 +1,43 @@
+using PixiEditor.ChangeableDocument.Rendering;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Text;
+
+[NodeInfo("CharacterPosition")]
+public class TextIndexOfNode : Node
+{
+    public OutputProperty<int> FirstIndex { get; }
+    
+    public OutputProperty<int> LastIndex { get; }
+    
+    public InputProperty<bool> MatchCase { get; }
+    
+    public InputProperty<string> Text { get; }
+    
+    public InputProperty<string> SearchText { get; }
+
+    public TextIndexOfNode()
+    {
+        FirstIndex = CreateOutput("FirstIndex", "FIRST_POSITION", -1);
+        LastIndex = CreateOutput("LastIndex", "LAST_POSITION", -1);
+        
+        MatchCase = CreateInput("MatchCase", "MATCH_CASE", false);
+        Text = CreateInput("Text", "TEXT", string.Empty);
+        SearchText = CreateInput("SearchText", "SEARCH_TEXT", string.Empty);
+    }
+
+    protected override void OnExecute(RenderContext context)
+    {
+        var comparisonMode = MatchCase.Value
+            ? StringComparison.InvariantCulture
+            : StringComparison.InvariantCultureIgnoreCase;
+
+        var text = Text.Value;
+        var searchText = SearchText.Value;
+
+        FirstIndex.Value = text.IndexOf(searchText, comparisonMode);
+        LastIndex.Value = text.LastIndexOf(searchText, comparisonMode);
+    }
+
+    public override Node CreateCopy() =>
+        new TextIndexOfNode();
+}

+ 6 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -1118,5 +1118,10 @@
   "MAX_BILINEAR_CANVAS_SIZE_DESC": "Maximum canvas size for bilinear filtering. Set to 0 to disable bilinear filtering. Bilinear filtering improves the quality of the canvas, but can cause performance issues on large canvases.",
   "INVERT_MASK": "Invert mask",
   "SLICE_TEXT": "Slice text",
-  "INDEX_START_AT": "Start at"
+  "INDEX_START_AT": "Start at",
+  "CHARACTER_POSITION_NODE": "Character Position",
+  "FIRST_POSITION": "First position",
+  "LAST_POSITION": "Last position",
+  "MATCH_CASE": "Match case",
+  "SEARCH_TEXT": "Search text"
 }

+ 7 - 0
src/PixiEditor/ViewModels/Document/Nodes/Text/TextIndexOfNodeViewModel.cs

@@ -0,0 +1,7 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Text;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes.Text;
+
+[NodeViewModel("CHARACTER_POSITION_NODE", "SHAPE", null)]
+internal class TextIndexOfNodeViewModel : NodeViewModel<TextIndexOfNode>;