From dd7739f95e581f41a28360083f2e83e2542d212a Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 16 Mar 2024 13:55:54 +0200 Subject: [PATCH 1/2] Avoid deserializing clipboard content in Custom Editor paste checks --- Source/Editor/CustomEditors/CustomEditor.cs | 15 +---------- .../CustomEditors/Editors/GenericEditor.cs | 27 +------------------ .../Surface/VisjectSurface.CopyPaste.cs | 20 +++++++------- 3 files changed, 12 insertions(+), 50 deletions(-) diff --git a/Source/Editor/CustomEditors/CustomEditor.cs b/Source/Editor/CustomEditors/CustomEditor.cs index ef6302e8e..3b7ccae5f 100644 --- a/Source/Editor/CustomEditors/CustomEditor.cs +++ b/Source/Editor/CustomEditors/CustomEditor.cs @@ -662,20 +662,7 @@ namespace FlaxEditor.CustomEditors /// /// Gets a value indicating whether can paste value from the system clipboard to the property value container. /// - public bool CanPaste - { - get - { - try - { - return GetClipboardObject(out _, false); - } - catch - { - return false; - } - } - } + public bool CanPaste => !string.IsNullOrEmpty(Clipboard.Text); /// /// Sets the value from the system clipboard. diff --git a/Source/Editor/CustomEditors/Editors/GenericEditor.cs b/Source/Editor/CustomEditors/Editors/GenericEditor.cs index 489e6aaba..0f4c70309 100644 --- a/Source/Editor/CustomEditors/Editors/GenericEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GenericEditor.cs @@ -474,32 +474,7 @@ namespace FlaxEditor.CustomEditors.Editors } if (layout.Editors.Count != 0) { - var sb = Clipboard.Text; - if (!string.IsNullOrEmpty(sb)) - { - try - { - var data = JsonSerializer.Deserialize(sb); - if (data == null || data.Length != layout.Editors.Count) - return false; - for (var i = 0; i < layout.Editors.Count; i++) - { - Clipboard.Text = data[i]; - if (!layout.Editors[i].CanPaste) - return false; - } - return true; - } - catch - { - return false; - } - finally - { - Clipboard.Text = sb; - } - } - return false; + return !string.IsNullOrEmpty(Clipboard.Text); } if (layout.Children.Any(x => x is LayoutElementsContainer)) { diff --git a/Source/Editor/Surface/VisjectSurface.CopyPaste.cs b/Source/Editor/Surface/VisjectSurface.CopyPaste.cs index 158492460..94d41a624 100644 --- a/Source/Editor/Surface/VisjectSurface.CopyPaste.cs +++ b/Source/Editor/Surface/VisjectSurface.CopyPaste.cs @@ -190,15 +190,7 @@ namespace FlaxEditor.Surface if (data == null || data.Length < 2) return false; - try - { - var model = JsonConvert.DeserializeObject(data); - return model?.Nodes != null && model.Nodes.Length != 0; - } - catch (Exception) - { - return false; - } + return true; } /// @@ -215,7 +207,15 @@ namespace FlaxEditor.Surface try { // Load Mr Json - var model = FlaxEngine.Json.JsonSerializer.Deserialize(data); + DataModel model; + try + { + model = FlaxEngine.Json.JsonSerializer.Deserialize(data); + } + catch + { + return; + } if (model.Nodes == null) model.Nodes = new DataModelNode[0]; From 7aa4ae17825cb19d5c6b6c2893f1bc2216420f90 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 16 Mar 2024 14:10:57 +0200 Subject: [PATCH 2/2] Fix assigning null values into value types in Custom Editor Resets back to previous value instead of setting the editor value to empty. --- Source/Editor/CustomEditors/CustomEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/CustomEditors/CustomEditor.cs b/Source/Editor/CustomEditors/CustomEditor.cs index 3b7ccae5f..5289a72af 100644 --- a/Source/Editor/CustomEditors/CustomEditor.cs +++ b/Source/Editor/CustomEditors/CustomEditor.cs @@ -650,7 +650,7 @@ namespace FlaxEditor.CustomEditors } } - if (obj == null || Values.Type.IsInstanceOfType(obj)) + if ((obj == null && !Values.Type.IsValueType) || Values.Type.IsInstanceOfType(obj)) { result = obj; return true;