Browse Source

Merge branch 'master' into fix/try-catch-update

Krzysztof Krysiński 1 week ago
parent
commit
d01030af9a

+ 1 - 1
src/PixiEditor/Views/Nodes/ConnectionRenderer.cs

@@ -51,7 +51,7 @@ public class ConnectionRenderer : Control
                     ? socket
                     : null;
 
-            if (inputSocket == null || outputSocket == null)
+            if (inputSocket == null || outputSocket == null || !inputSocket.IsVisible || !outputSocket.IsVisible)
             {
                 continue;
             }

+ 11 - 0
src/PixiEditor/Views/Overlays/Overlay.cs

@@ -160,6 +160,12 @@ public abstract class Overlay : Decorator, IOverlay // TODO: Maybe make it not a
         if (args.Handled) return;
         PointerPressedOverlay?.Invoke(args);
     }
+    
+    public void TextInput(string text)
+    {
+        if(SuppressEvents) return;
+        OnOverlayTextInput(text);
+    }
 
     public void ReleasePointer(OverlayPointerArgs args)
     {
@@ -350,6 +356,11 @@ public abstract class Overlay : Decorator, IOverlay // TODO: Maybe make it not a
     {
     }
 
+    protected virtual void OnOverlayTextInput(string text)
+    {
+        
+    }
+
     private static void OnZoomScaleChanged(AvaloniaPropertyChangedEventArgs<double> e)
     {
         if (e.Sender is Overlay overlay)

+ 22 - 19
src/PixiEditor/Views/Overlays/TextOverlay/TextOverlay.cs

@@ -127,6 +127,8 @@ internal class TextOverlay : Overlay
     private Paint opacityPaint;
     private Paint sampleTextPaint;
 
+    private bool canInsertText;
+
     private int lastXMovementCursorIndex;
 
     static TextOverlay()
@@ -209,10 +211,7 @@ internal class TextOverlay : Overlay
         };
 
         opacityPaint = new Paint() { Color = Colors.White.WithAlpha(ThemeResources.SelectionFillColor.A) };
-        sampleTextPaint = new Paint()
-        {
-            Color = Colors.Black, Style = PaintStyle.Fill, IsAntiAliased = true
-        };
+        sampleTextPaint = new Paint() { Color = Colors.Black, Style = PaintStyle.Fill, IsAntiAliased = true };
     }
 
 
@@ -472,6 +471,13 @@ internal class TextOverlay : Overlay
         return indexOfClosest;
     }
 
+    protected override void OnOverlayTextInput(string text)
+    {
+        if (!IsEditing || !canInsertText) return;
+
+        InsertTextAtCursor(text);
+    }
+
     protected override void OnKeyPressed(KeyEventArgs args)
     {
         if (!IsEditing) return;
@@ -484,16 +490,23 @@ internal class TextOverlay : Overlay
         if (IsRegisteredExternalShortcut(key, keyModifiers))
         {
             ShortcutController.UnblockShortcutExecution(nameof(TextOverlay));
+            canInsertText = false;
             return;
         }
 
         if (IsShortcut(key, keyModifiers))
         {
             ExecuteShortcut(key, keyModifiers);
+            canInsertText = false;
             return;
         }
 
-        InsertChar(key, args.KeySymbol);
+        if (key == Key.Tab)
+        {
+            args.Handled = true;
+        }
+
+        canInsertText = !TryInsertSpecialChar(key, args.KeySymbol);
     }
 
     private bool IsRegisteredExternalShortcut(Key key, KeyModifiers keyModifiers)
@@ -506,25 +519,15 @@ internal class TextOverlay : Overlay
         return ctxCommand != null;
     }
 
-    private void InsertChar(Key key, string symbol)
+    private bool TryInsertSpecialChar(Key key, string symbol)
     {
         if (key == Key.Enter)
         {
             InsertTextAtCursor("\n");
+            return true;
         }
-        else if (key == Key.Space)
-        {
-            InsertTextAtCursor(" ");
-        }
-        else
-        {
-            if (symbol is { Length: 1 })
-            {
-                char symbolChar = symbol[0];
-                if (char.IsControl(symbolChar)) return;
-                InsertTextAtCursor(symbol);
-            }
-        }
+
+        return false;
     }
 
     private void InsertTextAtCursor(string toAdd)

+ 20 - 0
src/PixiEditor/Views/Rendering/Scene.cs

@@ -647,6 +647,26 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
         }
     }
 
+    protected override void OnTextInput(TextInputEventArgs e)
+    {
+        base.OnTextInput(e);
+        try
+        {
+            if (AllOverlays != null)
+            {
+                foreach (Overlay overlay in AllOverlays)
+                {
+                    if (!overlay.IsVisible) continue;
+                    overlay.TextInput(e.Text);
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            CrashHelper.SendExceptionInfo(ex);
+        }
+    }
+
     private OverlayPointerArgs ConstructPointerArgs(PointerEventArgs e)
     {
         return new OverlayPointerArgs