Forge
csharpdeeb25a2
1#nullable enable
2
3using CascadeIDE.Features.Chat;
4
5namespace CascadeIDE.Features.Cockpit.Application;
6
7/// <summary>Единая синхронизация буфера CCL между view и <see cref="ChatPanelViewModel"/>.</summary>
8public static class CockpitCommandLineDraftBridge
9{
10 public static void ApplyDraftFromView(ChatPanelViewModel panel, string? text, int caretIndex)
11 {
12 var normalized = string.IsNullOrWhiteSpace(text) ? "/" : text;
13 var caret = Math.Clamp(caretIndex, 0, normalized.Length);
14 panel.CockpitCommandLineCaretIndex = caret;
15 if (!string.Equals(panel.CockpitCommandLineText, normalized, StringComparison.Ordinal))
16 panel.CockpitCommandLineText = normalized;
17 else
18 panel.RefreshCockpitCommandLineAutocomplete(normalized, caret);
19 }
20
21 public static void ApplyDraftFromViewModel(ChatPanelViewModel panel, Action<string> setText, Action<int> setCaret)
22 {
23 var text = panel.CockpitCommandLineText;
24 setText(text);
25 setCaret(Math.Clamp(panel.CockpitCommandLineCaretIndex, 0, text.Length));
26 }
27}
28
View only · write via MCP/CIDE