From 2dcfc7e3520806a64360b063d6589cf599704f68 Mon Sep 17 00:00:00 2001 From: Mika Kuns Date: Tue, 14 Apr 2026 10:33:45 +0200 Subject: [PATCH] feat(ui): add inline add handlers, checkbox click, and task keyboard shortcuts Co-Authored-By: Claude Sonnet 4.6 --- src/ClaudeDo.Ui/Views/TaskListView.axaml.cs | 88 ++++++++++++++++++--- 1 file changed, 76 insertions(+), 12 deletions(-) diff --git a/src/ClaudeDo.Ui/Views/TaskListView.axaml.cs b/src/ClaudeDo.Ui/Views/TaskListView.axaml.cs index 6fe82cf..c739070 100644 --- a/src/ClaudeDo.Ui/Views/TaskListView.axaml.cs +++ b/src/ClaudeDo.Ui/Views/TaskListView.axaml.cs @@ -1,5 +1,7 @@ using Avalonia.Controls; using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.VisualTree; using ClaudeDo.Ui.ViewModels; namespace ClaudeDo.Ui.Views; @@ -11,30 +13,92 @@ public partial class TaskListView : UserControl InitializeComponent(); } - private void OnTaskItemDoubleTapped(object? sender, TappedEventArgs e) + private void OnInlineAddKeyDown(object? sender, KeyEventArgs e) { - if (sender is Control c && c.DataContext is TaskItemViewModel - && DataContext is TaskListViewModel vm) + if (DataContext is not TaskListViewModel vm) return; + + if (e.Key == Key.Enter) { - vm.EditTaskCommand.Execute(null); + vm.InlineAddCommand.Execute(null); e.Handled = true; } + else if (e.Key == Key.Escape) + { + vm.InlineAddTitle = ""; + this.FindControl("TaskListBox")?.Focus(); + e.Handled = true; + } + } + + private void OnInlineAddGotFocus(object? sender, FocusChangedEventArgs e) + { + if (sender is TextBox tb) + tb.BorderBrush = Avalonia.Application.Current?.FindResource("AccentBrush") as Avalonia.Media.IBrush; + } + + private void OnInlineAddLostFocus(object? sender, RoutedEventArgs e) + { + if (sender is TextBox tb) + tb.BorderBrush = Avalonia.Application.Current?.FindResource("BorderSubtleBrush") as Avalonia.Media.IBrush; + } + + private void OnTaskListKeyDown(object? sender, KeyEventArgs e) + { + if (DataContext is not TaskListViewModel vm || vm.SelectedTask is null) return; + + switch (e.Key) + { + case Key.Delete: + vm.DeleteTaskCommand.Execute(null); + e.Handled = true; + break; + case Key.Space: + if (vm.SelectedTask.CanToggleDone) + { + vm.SelectedTask.ToggleDoneCommand.Execute(null); + e.Handled = true; + } + break; + case Key.Enter: + case Key.F2: + var detailView = this.GetVisualAncestors().OfType().FirstOrDefault() + ?.GetVisualDescendants().OfType().FirstOrDefault(); + detailView?.FocusTitle(); + e.Handled = true; + break; + } + } + + private void OnCheckboxPressed(object? sender, PointerPressedEventArgs e) + { + if (sender is not Border { DataContext: TaskItemViewModel task }) return; + if (task.CanToggleDone) + { + task.ToggleDoneCommand.Execute(null); + e.Handled = true; + } + } + + private void OnTaskItemDoubleTapped(object? sender, TappedEventArgs e) + { + if (DataContext is TaskListViewModel vm) + vm.EditTaskCommand.Execute(null); } private void OnTaskItemPointerPressed(object? sender, PointerPressedEventArgs e) { - if (e.GetCurrentPoint(null).Properties.PointerUpdateKind == PointerUpdateKind.RightButtonPressed - && sender is Control c && c.DataContext is TaskItemViewModel item + var props = e.GetCurrentPoint(this).Properties; + if (!props.IsRightButtonPressed) return; + + if (sender is Grid { DataContext: TaskItemViewModel item } && DataContext is TaskListViewModel vm) { vm.SelectedTask = item; - e.Handled = true; } } - private void OnInlineAddKeyDown(object? sender, Avalonia.Input.KeyEventArgs e) { } - private void OnInlineAddGotFocus(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { } - private void OnInlineAddLostFocus(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { } - private void OnTaskListKeyDown(object? sender, Avalonia.Input.KeyEventArgs e) { } - private void OnCheckboxPressed(object? sender, Avalonia.Input.PointerPressedEventArgs e) { } + public void FocusInlineAdd() + { + this.FindControl("InlineAddBox")?.Focus(); + } }