csharpdeeb25a2 | 1 | using Avalonia.Controls; |
| 2 | using Avalonia.Input; |
| 3 | using Avalonia.Threading; |
| 4 | |
| 5 | namespace CascadeIDE.Views; |
| 6 | |
| 7 | public partial class MainWindow |
| 8 | { |
| 9 | private IInputElement? _focusBeforeCommandPalette; |
| 10 | |
| 11 | /// <summary>Сохранение и восстановление фокуса при открытии/закрытии палитры команд (UX §6).</summary> |
| 12 | internal void HandleCommandPaletteOpenStateChanged(bool open) |
| 13 | { |
| 14 | if (open) |
| 15 | { |
| 16 | _focusBeforeCommandPalette = FocusManager?.GetFocusedElement(); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | var prev = _focusBeforeCommandPalette; |
| 21 | _focusBeforeCommandPalette = null; |
| 22 | Dispatcher.UIThread.Post(() => |
| 23 | { |
| 24 | if (prev is Control c) |
| 25 | c.Focus(); |
| 26 | }, DispatcherPriority.Background); |
| 27 | } |
| 28 | } |
| 29 | |
View only · write via MCP/CIDE