Skip to content

Commit d951f6c

Browse files
💾 Feat(Blueprint): 修复 Branch 端口排序与编辑器防抖
- BlueprintEditorViewModel: Branch 节点输出引脚按 descriptor.RelativeY 排序(True在上/False在下), 替代字母序排序 - WorkflowScriptEditorWindow: TextChanged 添加 500ms 防抖, 减少频繁重解析
1 parent af1f910 commit d951f6c

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

KitX Dashboard/ViewModels/BlueprintEditorViewModel.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,16 @@ private BlueprintNodeVM ConvertBlueprintNodeToViewModel(BlueprintNode blueprintN
544544
Output = new ObservableCollection<object>()
545545
};
546546

547-
// Add input connectors (execution pins first, then data pins)
547+
// Build RelativeY lookup from descriptor for correct pin ordering
548+
var inputRelativeY = descriptor.InputPins
549+
.ToDictionary(p => p.Name, p => p.RelativeY);
550+
var outputRelativeY = descriptor.OutputPins
551+
.ToDictionary(p => p.Name, p => p.RelativeY);
552+
553+
// Add input connectors (execution pins first, then data pins, ordered by RelativeY)
548554
foreach (var pin in blueprintNode.InputPins
549555
.OrderByDescending(p => p.Type == PinType.Execution)
550-
.ThenBy(p => p.Name))
556+
.ThenBy(p => inputRelativeY.GetValueOrDefault(p.Name, 0)))
551557
{
552558
var connector = new BlueprintConnectorVM
553559
{
@@ -560,10 +566,10 @@ private BlueprintNodeVM ConvertBlueprintNodeToViewModel(BlueprintNode blueprintN
560566
nodeVm.Input.Add(connector);
561567
}
562568

563-
// Add output connectors
569+
// Add output connectors (ordered by RelativeY to match descriptor layout)
564570
foreach (var pin in blueprintNode.OutputPins
565571
.OrderByDescending(p => p.Type == PinType.Execution)
566-
.ThenBy(p => p.Name))
572+
.ThenBy(p => outputRelativeY.GetValueOrDefault(p.Name, 0)))
567573
{
568574
var connector = new BlueprintConnectorVM
569575
{

KitX Dashboard/Views/WorkflowScriptEditorWindow.axaml.cs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Linq;
3+
using System.Threading;
34
using System.Threading.Tasks;
45
using Avalonia.Controls;
6+
using Avalonia.Threading;
57
using KitX.Dashboard.ViewModels;
68
using AvaloniaEdit;
79
using Avalonia.Interactivity;
@@ -23,6 +25,7 @@ public partial class WorkflowScriptEditorWindow : Window, IView
2325
private readonly WorkflowScriptEditorWindowViewModel viewModel;
2426
private bool _isEditingHelperFunction = false;
2527
private bool _isUpdatingOutput = false;
28+
private CancellationTokenSource? _debounceCts;
2629

2730
public WorkflowScriptEditorWindow()
2831
{
@@ -141,32 +144,41 @@ private void Initialize()
141144
WorkflowOutput.WriteLine(""Done!"");";
142145
}
143146

144-
// 订阅代码变化事件
147+
// 订阅代码变化事件(带防抖)
145148
codeEditor.TextChanged += (s, e) =>
146149
{
147-
if (codeEditor.Document != null)
150+
if (codeEditor.Document == null) return;
151+
152+
// Helper function editing: sync immediately (no debounce needed)
153+
if (_isEditingHelperFunction)
148154
{
149-
if (_isEditingHelperFunction)
155+
if (viewModel.SelectedHelperFunction != null)
150156
{
151-
// 正在编辑辅助函数,同步代码到 SelectedHelperFunction.Code
152-
if (viewModel.SelectedHelperFunction != null)
153-
{
154-
viewModel.SelectedHelperFunction.Code = codeEditor.Document.Text;
155-
}
157+
viewModel.SelectedHelperFunction.Code = codeEditor.Document.Text;
156158
}
157-
else
159+
return;
160+
}
161+
162+
// Main program editing: debounce parse-heavy operations
163+
viewModel.MainProgramCode = codeEditor.Document.Text;
164+
165+
_debounceCts?.Cancel();
166+
_debounceCts = new CancellationTokenSource();
167+
var token = _debounceCts.Token;
168+
169+
_ = Task.Delay(500, token).ContinueWith(t =>
170+
{
171+
if (t.IsCanceled) return;
172+
Dispatcher.UIThread.InvokeAsync(() =>
158173
{
159-
// 正在编辑主程序
160-
viewModel.MainProgramCode = codeEditor.Document.Text;
161-
// 解析常量
174+
if (codeEditor.Document == null) return;
162175
viewModel.ParseConstantsFromCode(codeEditor.Document.Text);
163-
// 更新UI
164176
if (constantsItemsControl != null)
165177
{
166178
constantsItemsControl.ItemsSource = viewModel.VariableConstants;
167179
}
168-
}
169-
}
180+
});
181+
}, token);
170182
};
171183
}
172184

0 commit comments

Comments
 (0)