╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2475 2476 fn viewStack(self: *This) *wgt.Stack(Widget) { 2477 return &self.box.children.values()[stack_index].widget.stack; 2478 } 2479 2480 // `index`'s master-detail split inside the stack. 2481 fn resultsBox(self: *This, index: usize) *wgt.Box(Widget) { 2482 return &self.viewStack().children.values()[index].box; 2483 } 2484 2485 // the labels view's flow inside the stack. 2486 fn labelsView(self: *This) *WordFlow { 2487 return &self.viewStack().children.values()[labels_view_index].word_flow; 2488 } 2489 2490 // no labels, which shows the empty message 2491 fn labelsEmpty(data: *const Self) bool { 2492 return data.labels.len == 0; 2493 } 2494 2495 // the non-confirmation form inside the stack 2496 fn formBox(self: *This) ?*wgt.Box(Widget) { 2497 return switch (self.viewStack().children.values()[form_view_index]) { 2498 .box => |*box| box, 2499 // the resolve form sits inside a scroll on the terminal 2500 .scroll => |*scroll| &scroll.child.box, 2501 else => null, 2502 }; 2503 } 2504 2505 fn threadForm(self: *This) ?*wgt.Box(Widget) { 2506 if (supports_conflicts and self.data.view == .resolve) return null; 2507 return switch (self.data.view) { 2508 .new_comment, .edit_comment => null, 2509 else => self.formBox(), 2510 }; 2511 } 2512 2513 fn formField(form: *wgt.Box(Widget), name: []const u8) !*wgt.TextInput { 2514 for (form.children.values()) |*child| switch (child.widget) { 2515 .text_input => |*text_input| if (std.mem.eql(u8, text_input.options.name, name)) return text_input, 2516 else => {}, 2517 }; 2518 return error.MissingFormField; 2519 } 2520 2521 fn formWidget(form: *wgt.Box(Widget), comptime widget_kind: std.meta.Tag(Widget)) ?*@FieldType(Widget, @tagName(widget_kind)) { 2522 for (form.children.values()) |*child| { 2523 if (child.widget == widget_kind) return &@field(child.widget, @tagName(widget_kind)); 2524 } 2525 return null; 2526 } 2527 2528 fn confirmationForm(self: *This) ?*wgt.Box(Widget) { 2529 return switch (self.viewStack().children.values()[form_view_index]) { 2530 .center => |*center| switch (center.child.*) { 2531 .box => |*box| box, 2532 else => null, 2533 }, 2534 else => null, 2535 }; 2536 } 2537 2538 // the resolve form's scroll on the terminal (the web page scrolls itself) 2539 fn resolveScroll(self: *This) ?*wgt.Scroll(Widget) { 2540 return switch (self.viewStack().children.values()[form_view_index]) { 2541 .scroll => |*scroll| scroll, 2542 else => null, 2543 }; 2544 } 2545 2546 fn listScroll(self: *This, index: usize) *wgt.Scroll(Widget) { 2547 return &self.resultsBox(index).children.values()[list_index].widget.scroll; 2548 } 2549 2550 fn listBox(self: *This, index: usize) *wgt.Box(Widget) { 2551 return &self.listScroll(index).child.box; 2552 } 2553 2554 fn detailFrame(self: *This, index: usize) *wgt.Box(Widget) { 2555 return &self.resultsBox(index).children.values()[detail_index].widget.box; 2556 } 2557 2558 fn detail(self: *This, index: usize) *DetailType { 2559 return &@field(self.detailFrame(index).children.values()[widget.list_pane_index].widget, Data.detail_widget_name); 2560 } 2561 2562 fn window(self: *This, index: usize) *const Window { 2563 if (supports_conflicts and index == conflict_view_index) return &self.data.conflicts; 2564 if (supports_drafts and index == drafts_view_index) return &self.data.drafts; 2565 return self.data.window(splitStatus(index)); 2566 } 2567 2568 // an empty first window, which shows the empty message 2569 fn windowEmpty(win: *const Window) bool { 2570 return win.items.len == 0 and win.prev_id == null; 2571 } 2572 2573 fn stackSelectedIndex(self: *This) ?usize { 2574 const stack = self.viewStack(); 2575 const cid = stack.getFocus().child_id orelse return null; 2576 return stack.children.getIndex(cid); 2577 } 2578 2579 // the stack's selected master-detail split (null when the labels view, the 2580 // new-thread form, or the empty message shows). 2581 fn selectedSplitIndex(self: *This) ?usize { 2582 const idx = self.stackSelectedIndex() orelse return null; 2583 const split = idx < status_count or (supports_drafts and idx == drafts_view_index) or idx == conflict_view_index; 2584 return if (split and !windowEmpty(self.window(idx))) idx else null; 2585 } 2586 2587 fn detailActive(self: *This, index: usize) bool { 2588 const rb = self.resultsBox(index); 2589 const cid = rb.getFocus().child_id orelse return false; 2590 return rb.children.getIndex(cid) == detail_index; 2591 } 2592 2593 fn headerActive(self: *This) bool { 2594 const cid = self.box.getFocus().child_id orelse return false; 2595 return self.box.children.getIndex(cid) == header_index; 2596 } 2597 2598 fn labelsViewActive(self: *This) bool { 2599 if (self.headerActive()) return false; 2600 return self.stackSelectedIndex() == labels_view_index; 2601 } 2602 2603 fn formViewActive(self: *This) bool { 2604 if (self.headerActive()) return false; 2605 return self.stackSelectedIndex() == form_view_index; 2606 } 2607 2608 // the selected thread's index, or null when a window-navigation row is 2609 // selected (a leading "previous" row shifts the thread rows down by one). 2610 fn selectedThreadIndex(self: *This, index: usize) ?usize { 2611 const lb = self.listBox(index); 2612 const cid = lb.getFocus().child_id orelse return null; 2613 const idx = lb.children.getIndex(cid) orelse return null; 2614 const win = self.window(index); 2615 const lead: usize = if (win.prev_id != null) 1 else 0; 2616 if (idx < lead or idx - lead >= win.items.len) return null; 2617 return idx - lead; 2618 } 2619 2620 // swap the detail pane to the selected thread when it changes 2621 fn refreshDetail(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2622 const selected = self.selectedThreadIndex(index) orelse return; 2623 const entry = self.window(index).items[selected]; 2624 const changed = if (self.detail(index).entry) |current| !std.mem.eql(u8, current.id, entry.id) else true; 2625 if (!changed) return; 2626 try self.detail(index).setEntry(allocator, entry); 2627 widget.setListBackLink(self.detailFrame(index), try rowLink(self.session.page_arena, self.data, entry.id)); 2628 } 2629 2630 pub fn build(self: *This, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2631 self.clearGrid(); 2632 2633 // each header tab maps 1:1 to a stack child by position 2634 if (self.header().getSelectedIndex()) |index| { 2635 const stack = self.viewStack(); 2636 stack.getFocus().child_id = stack.children.keys()[index]; 2637 } 2638 2639 if (self.selectedSplitIndex()) |i| { 2640 // whether the detail pane fits beside the list, which decides 2641 // the list cap below and whether the detail carries a way back 2642 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 2643 try self.refreshDetail(allocator, i); 2644 widget.showListBack(self.detailFrame(i), !both_panes_fit); 2645 2646 // the selected list row shows a border (the focused TextBox 2647 // upgrades it to a double border itself); the rest stay borderless. 2648 const lb = self.listBox(i); 2649 for (lb.children.keys(), lb.children.values()) |id, *child| { 2650 switch (child.widget) { 2651 .text_box => |*tb| widget.markSelected(tb, lb.getFocus().child_id == id), 2652 else => {}, 2653 } 2654 } 2655 2656 // cap the list at list_max_width only while the detail pane fits 2657 // beside it. the box drops the detail when the width can't hold 2658 // both minimums, so when it's that narrow we lift the cap and let 2659 // the list fill the whole width. 2660 self.resultsBox(i).children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 2661 2662 // stretch the detail pane across the rest of the width so it fills 2663 // the area rather than shrinking to its content; its scroll fills 2664 // the pane. 2665 if (constraint.max_size.width) |w| { 2666 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = if (both_panes_fit) w - list_max_width else w, .height = null }; 2667 } else { 2668 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 2669 } 2670 } 2671 2672 // refresh the form inputs' entries in the session's focus-id -> input 2673 // map with this frame's addresses, so the web/wasm form handling can 2674 // find them by focus id 2675 if (self.threadForm()) |form| { 2676 const failure = if (self.session.formFeedback(feedback_tag)) |saved| saved.failure else null; 2677 (try formField(form, "title")).options.top_label.text = if (failure == .required_title) " title (required) " else " title "; 2678 if (comptime supports_drafts) { 2679 if (formWidget(form, .patch_source)) |source| { 2680 source.field().options.top_label.text = if (failure == .invalid_source_branch) " source branch (not found) " else if (failure == .same_branch) " source branch (same as target) " else if (failure == .unrelated_branches) " source branch (unrelated) " else " source branch "; 2681 const submit = formWidget(form, .submit_button) orelse return error.MissingFormField; 2682 try submit.setLabel(allocator, switch (source.selectedKind()) { 2683 .fork => "submit draft", 2684 .branch => "submit patch", 2685 }); 2686 } 2687 (try formField(form, "target_branch")).options.top_label.text = 2688 if (failure == .invalid_target_branch) " target branch (invalid) " else if (self.data.view == .edit and failure == .same_branch) " target branch (same as source) " else if (self.data.view == .edit and failure == .unrelated_branches) " target branch (unrelated to source) " else if (self.data.view == .edit and failure == .invalid_source_branch) " target branch (source branch not found) " else " target branch "; 2689 } 2690 } 2691 if (self.formBox()) |form| { 2692 const inputs_arena = self.session.arena.allocator(); 2693 for (form.children.values()) |*child| switch (child.widget) { 2694 .text_input => |*ti| try self.session.text_inputs.put(inputs_arena, ti.getFocus().id, ti), 2695 else => {}, 2696 }; 2697 } 2698 2699 try self.box.build(allocator, constraint, root_focus); 2700 } 2701 2702 pub fn input(self: *This, allocator: std.mem.Allocator, raw_key: Key, root_focus: *Focus) !void { 2703 // wheel input moves focus like the arrows 2704 const key: Key = switch (raw_key) { 2705 .scroll_up => .arrow_up, 2706 .scroll_down => .arrow_down, 2707 else => raw_key, 2708 }; 2709 2710 if (self.headerActive()) { 2711 // down from the sub-header re-enters the stack if the selected 2712 // view has something to focus; enter in the search box submits 2713 // the query; other keys move within the sub-header. 2714 if (inp.vertDirection(key) == .down) { 2715 const enterable = if (self.stackSelectedIndex()) |idx| 2716 if (idx == labels_view_index) 2717 !labelsEmpty(self.data) 2718 else if (idx == form_view_index) 2719 // nothing focusable in the unauthorized view 2720 self.viewStack().children.values()[idx] != .unauthorized 2721 else 2722 !windowEmpty(self.window(idx)) 2723 else 2724 false; 2725 if (enterable) root_focus.setFocus(self.box.children.keys()[stack_index]); 2726 } else if (key == .enter) { 2727 if (try self.header().submittedText(allocator)) |text| { 2728 defer allocator.free(text); 2729 try self.submitSearch(text); 2730 } 2731 } else { 2732 try self.header().input(allocator, key, root_focus); 2733 } 2734 return; 2735 } 2736 if (self.labelsViewActive()) { 2737 self.labelsViewInput(key, root_focus); 2738 return; 2739 } 2740 if (self.formViewActive()) { 2741 if (confirmation(self.data.view) != null) { 2742 try self.confirmationFormInput(allocator, key, root_focus); 2743 } else if (supports_conflicts and self.data.view == .resolve) { 2744 try self.resolveInput(allocator, key, root_focus); 2745 } else { 2746 try self.formInput(allocator, key, root_focus); 2747 } 2748 return; 2749 } 2750 const i = self.selectedSplitIndex() orelse return; 2751 if (self.detailActive(i)) { 2752 // the way back to the list, by enter or a click 2753 if (widget.listBackId(self.detailFrame(i))) |id| { 2754 if (inp.activated(root_focus, id, key)) return self.focusList(i, root_focus); 2755 if (root_focus.grandchild_id == id) return switch (key) { 2756 .arrow_left => self.focusList(i, root_focus), 2757 .arrow_up => self.focusHeader(root_focus), 2758 .arrow_down => _ = self.detail(i).focusFirst(root_focus), 2759 else => {}, 2760 }; 2761 } 2762 switch (try self.detail(i).inputWithExit(allocator, key, root_focus)) { 2763 .none => {}, 2764 .list => self.focusList(i, root_focus), 2765 .header => if (widget.listBackId(self.detailFrame(i))) |id| root_focus.setFocus(id) else self.focusHeader(root_focus), 2766 } 2767 } else { 2768 try self.listInput(allocator, i, key, root_focus); 2769 } 2770 } 2771 2772 // navigate to the typed query's results, keeping the status list the 2773 // page shows. an empty box clears a filtered page and does nothing on 2774 // any other one. 2775 fn submitSearch(self: *This, text: []const u8) !void { 2776 if (text.len == 0 and self.data.search == null) return; 2777 const selected = self.header().getSelectedIndex() orelse 0; 2778 const status: Status = if (selected < status_count) splitStatus(selected) else @fromBackingInt(@intCast(0)); 2779 const route = listRoute(self.data.identity, status, "") orelse return; 2780 try self.session.navigate(route.withSearch(text) orelse return); 2781 } 2782 2783 // arrow keys move the label selection; up from the top row crosses to the 2784 // header tabs. 2785 fn labelsViewInput(self: *This, key: Key, root_focus: *Focus) void { 2786 const tf = self.labelsView(); 2787 const cid = tf.focus.child_id orelse return; 2788 const cur = tf.indexOfFocusId(cid) orelse return; 2789 const count = tf.text_boxes.items.len; 2790 switch (key) { 2791 .arrow_left => if (cur > 0) root_focus.setFocus(tf.text_boxes.items[cur - 1].getFocus().id), 2792 .arrow_right => if (cur + 1 < count) root_focus.setFocus(tf.text_boxes.items[cur + 1].getFocus().id), 2793 .arrow_up => if (tf.rowStep(cur, false)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id) else self.focusHeader(root_focus), 2794 .arrow_down => if (tf.rowStep(cur, true)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id), 2795 .home => root_focus.setFocus(tf.text_boxes.items[0].getFocus().id), 2796 .end => root_focus.setFocus(tf.text_boxes.items[count - 1].getFocus().id), 2797 else => {}, 2798 } 2799 } 2800 2801 fn listInput(self: *This, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !void { 2802 // up/down (and the scroll wheel) move the selection a row; page up/down 2803 // jump a fixed amount. right/Enter cross into the detail pane. up from 2804 // the top row crosses into the header tabs. 2805 if (inp.rowDelta(key, @intCast(self.listBox(index).children.count()))) |delta| { 2806 const lb = self.listBox(index); 2807 const at_top = if (lb.getFocus().child_id) |cid| lb.children.getIndex(cid) == 0 else true; 2808 if (delta < 0 and at_top) return self.focusHeader(root_focus); 2809 moveRowFocus(lb, self.listScroll(index), root_focus, delta); 2810 return; 2811 } 2812 switch (key) { 2813 .enter, .arrow_right => self.focusDetail(index, root_focus), 2814 // when the window is too narrow to lay out the detail pane beside 2815 // the list, a click on a row opens it like enter. the row was just 2816 // selected, so the detail is swapped to it ahead of the build. 2817 .mouse => |mouse| if (self.resultsBox(index).children.values()[detail_index].rect == null and widget.clickOnSelectedRow(self.listBox(index), root_focus, mouse)) { 2818 try self.refreshDetail(allocator, index); 2819 self.focusDetail(index, root_focus); 2820 }, 2821 else => {}, 2822 } 2823 } 2824 2825 fn formInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2826 const form = self.formBox() orelse return; 2827 const cid = form.getFocus().child_id orelse return; 2828 const cur = form.children.getIndex(cid) orelse return; 2829 const child = &form.children.values()[cur]; 2830 2831 if (child.widget == .text_input) { 2832 const text_input = &child.widget.text_input; 2833 if (text_input.options.multiline and try multilineKeepsKey(text_input, allocator, key)) 2834 return child.widget.input(allocator, key, root_focus); 2835 } 2836 2837 const on_submit = child.widget == .submit_button; 2838 switch (key) { 2839 .arrow_up, .back_tab => return if (formStep(form, cur, false)) |i| 2840 root_focus.setFocus(form.children.keys()[i]) 2841 else 2842 self.focusHeader(root_focus), 2843 .arrow_down, .tab => return if (formStep(form, cur, true)) |i| root_focus.setFocus(form.children.keys()[i]), 2844 .enter => if (on_submit) return self.submitForm(allocator), 2845 .mouse => |mouse| if (on_submit) { 2846 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) return self.submitForm(allocator); 2847 }, 2848 else => {}, 2849 } 2850 try child.widget.input(allocator, key, root_focus); 2851 } 2852 2853 fn confirmationFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2854 const form = self.confirmationForm() orelse return; 2855 const child_id = form.getFocus().child_id orelse return; 2856 const index = form.children.getIndex(child_id) orelse return; 2857 switch (key) { 2858 .arrow_up, .back_tab => if (index > 1) 2859 root_focus.setFocus(form.children.keys()[index - 1]) 2860 else 2861 self.focusHeader(root_focus), 2862 .arrow_down, .tab => if (index + 1 < form.children.count()) root_focus.setFocus(form.children.keys()[index + 1]), 2863 .enter => try self.submitConfirmation(allocator, index), 2864 .mouse => |mouse| for (form.children.keys()[1..], 1..) |button_id, button_index| { 2865 if (inp.leftClickOn(root_focus, button_id, mouse)) { 2866 try self.submitConfirmation(allocator, button_index); 2867 break; 2868 } 2869 }, 2870 else => {}, 2871 } 2872 } 2873 2874 // the multiline hunk inputs keep enter and any up/down that has a row to 2875 // move to; enter on a "use this" link is a navigation the host follows 2876 // before this runs. 2877 fn resolveInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2878 const form = self.formBox() orelse return; 2879 const cid = form.getFocus().child_id orelse return; 2880 const cur = form.children.getIndex(cid) orelse return; 2881 const child = &form.children.values()[cur]; 2882 2883 if (child.widget == .text_input) { 2884 const ti = &child.widget.text_input; 2885 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2886 return child.widget.input(allocator, key, root_focus); 2887 } 2888 2889 const on_submit = child.widget == .submit_button; 2890 2891 switch (key) { 2892 .arrow_up, .back_tab => if (formStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2893 .arrow_down, .tab => if (formStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2894 .arrow_left, .arrow_right => switch (child.widget) { 2895 .box => |*row| _ = widget.moveInRow(row, root_focus, key == .arrow_right), 2896 else => try child.widget.input(allocator, key, root_focus), 2897 }, 2898 .enter => if (on_submit) try self.submitResolution(allocator), 2899 .mouse => |mouse| if (on_submit) { 2900 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2901 }, 2902 else => try child.widget.input(allocator, key, root_focus), 2903 } 2904 } 2905 2906 // a multiline input keeps enter and any up/down that has a row to move to 2907 fn multilineKeepsKey(text_input: *wgt.TextInput, allocator: std.mem.Allocator, key: Key) !bool { 2908 return switch (key) { 2909 .enter => true, 2910 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2911 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2912 else => false, 2913 }; 2914 } 2915 2916 // the neighboring form control, skipping spacers and blank rows 2917 fn formStep(form: *wgt.Box(Widget), cur: usize, down: bool) ?usize { 2918 var i = cur; 2919 while (true) { 2920 if (down) { 2921 i += 1; 2922 if (i >= form.children.count()) return null; 2923 } else { 2924 if (i == 0) return null; 2925 i -= 1; 2926 } 2927 const child = &form.children.values()[i]; 2928 if (child.hidden) continue; 2929 switch (child.widget) { 2930 .spacer, .text => continue, 2931 else => return i, 2932 } 2933 } 2934 } 2935 2936 // focus the resolve-form child at `i` (a version row focuses its selected 2937 // child) and keep it visible on the terminal 2938 fn focusResolveChild(self: *This, form: *wgt.Box(Widget), i: usize, root_focus: *Focus) void { 2939 const child = &form.children.values()[i]; 2940 switch (child.widget) { 2941 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2942 else => root_focus.setFocus(form.children.keys()[i]), 2943 } 2944 if (self.session.is_terminal) { 2945 if (self.resolveScroll()) |sc| { 2946 if (child.rect) |rect| sc.scrollToRect(rect); 2947 } 2948 } 2949 } 2950 2951 // re-emit the conflicted thread's event with the resolved content; any 2952 // event on the thread settles its conflict entry. this is the terminal 2953 // path; the web posts the form to the resolve route. 2954 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 2955 if (comptime wasm) return; 2956 const io = self.session.io orelse return; 2957 const src = self.data.repo_source orelse return; 2958 const entry = self.data.selectedThread() orelse return; 2959 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 2960 const form = self.formBox() orelse return; 2961 2962 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2963 var title: ?[]u8 = null; 2964 var labels: ?[]u8 = null; 2965 var hunks: std.ArrayList([]const u8) = .empty; 2966 defer { 2967 if (title) |t| allocator.free(t); 2968 if (labels) |t| allocator.free(t); 2969 for (hunks.items) |h| allocator.free(h); 2970 hunks.deinit(allocator); 2971 } 2972 for (form.children.values()) |*child| switch (child.widget) { 2973 .text_input => |*ti| { 2974 const text = try ti.text(allocator); 2975 errdefer allocator.free(text); 2976 if (std.mem.eql(u8, ti.options.name, "title")) { 2977 title = text; 2978 } else if (std.mem.eql(u8, ti.options.name, "labels")) { 2979 labels = text; 2980 } else { 2981 try hunks.append(allocator, text); 2982 } 2983 }, 2984 else => {}, 2985 }; 2986 2987 const id_bytes = try evt.parseEventId(entry.id); 2988 2989 switch (src.repo_kind) { 2990 inline else => |repo_kind| { 2991 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2992 defer any_repo.deinit(io, allocator); 2993 switch (any_repo) { 2994 inline else => |*repo| { 2995 var resolution: Event.Resolve = .{ 2996 .title = title, 2997 .labels = labels, 2998 .hunks = hunks.items, 2999 }; 3000 if (comptime @hasField(Event.Resolve, "theirs")) resolution.theirs = self.data.theirs_picks; 3001 const change = Event.Update{ .resolve = resolution }; 3002 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, change, author) catch |err| switch (err) { 3003 // leave the form up for correction 3004 error.InvalidFields => return, 3005 else => |e| return e, 3006 }; 3007 }, 3008 } 3009 }, 3010 } 3011 3012 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3013 try self.session.navigate(route); 3014 } 3015 3016 // commit a new or edited comment and navigate to its permalink. this is the 3017 // terminal path; the web posts the form to its comment route. 3018 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 3019 if (comptime wasm) return; 3020 const io = self.session.io orelse return; 3021 const src = self.data.repo_source orelse return; 3022 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3023 const author = actor.author; 3024 const form = self.formBox() orelse return; 3025 const body_input = try formField(form, "body"); 3026 const body = try body_input.text(allocator); 3027 defer allocator.free(body); 3028 if (!evt.Comment.fieldsValid(body)) return; 3029 3030 var thread_id: [evt.event_id_size * 2]u8 = undefined; 3031 @memcpy(&thread_id, self.data.selected_id); 3032 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 3033 var parent: [evt.event_id_size * 2]u8 = undefined; 3034 @memcpy(&parent, self.data.comment_id); 3035 break :blk parent; 3036 }; 3037 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 3038 const editing = self.data.view == .edit_comment; 3039 if (editing) { 3040 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3041 if (!try src.canModify(io, allocator, actor, .comment, &comment_id)) return; 3042 } 3043 switch (src.repo_kind) { 3044 inline else => |repo_kind| { 3045 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3046 defer any_repo.deinit(io, allocator); 3047 switch (any_repo) { 3048 inline else => |*repo| if (editing) { 3049 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3050 try evt.Comment.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &comment_id, body, author); 3051 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 3052 } else { 3053 event_id_hex = try evt.Comment.create(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &parent_id, body, author); 3054 }, 3055 } 3056 }, 3057 } 3058 3059 body_input.clear(allocator); 3060 const route = ui.RoutablePage.repoThreadCommentRoute(kind, self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 3061 try self.session.navigate(route); 3062 } 3063 3064 // terminal form submissions; the web posts to the forms' routes instead 3065 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 3066 switch (self.data.view) { 3067 .new_comment, .edit_comment => try self.submitComment(allocator), 3068 .edit => try self.submitEditedThread(allocator), 3069 else => try self.submitNewThread(allocator), 3070 } 3071 } 3072 3073 // commit the new thread to the repo's events branch and navigate to it. 3074 // this is the terminal path; the web posts the form to the thread route, 3075 // so the wasm side never runs (or compiles) the repo access below. 3076 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 3077 if (comptime wasm) return; 3078 const io = self.session.io orelse return; 3079 const src = self.data.repo_source orelse return; 3080 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3081 3082 const form = self.threadForm() orelse return; 3083 const title_input = try formField(form, "title"); 3084 const labels_input = try formField(form, "labels"); 3085 const description_input = try formField(form, "description"); 3086 3087 const title = try title_input.text(allocator); 3088 defer allocator.free(title); 3089 const labels = try labels_input.text(allocator); 3090 defer allocator.free(labels); 3091 const description = try description_input.text(allocator); 3092 defer allocator.free(description); 3093 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3094 defer if (comptime supports_drafts) allocator.free(target_branch); 3095 3096 if (!Event.fieldsValid(title, labels)) { 3097 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3098 return; 3099 } 3100 3101 if (comptime supports_drafts) { 3102 const source = formWidget(form, .patch_source) orelse return error.MissingFormField; 3103 const source_branch = switch (source.selectedKind()) { 3104 .fork => null, 3105 .branch => try source.field().text(allocator), 3106 }; 3107 defer if (source_branch) |branch| allocator.free(branch); 3108 const event_id_hex = Data.create(self.data, self.session, allocator, actor, title, labels, description, target_branch, source_branch) catch |err| { 3109 const failure = FeedbackFailure.fromError(err) orelse return err; 3110 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3111 return; 3112 }; 3113 title_input.clear(allocator); 3114 labels_input.clear(allocator); 3115 description_input.clear(allocator); 3116 (try formField(form, "target_branch")).clear(allocator); 3117 const route = ui.RoutablePage.repoThreadCommentsRoute(kind, self.data.identity, &event_id_hex, 0) orelse return; 3118 try self.session.navigate(route); 3119 return; 3120 } 3121 3122 var id_bytes: [evt.event_id_size]u8 = undefined; 3123 io.random(&id_bytes); 3124 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 3125 3126 const event = evt.EventWithId{ 3127 .id = event_id_hex, 3128 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 3129 .author = actor.author, 3130 .event = @unionInit(evt.Event, @tagName(kind), Event{ 3131 .title = title, 3132 .description = description, 3133 .labels = labels, 3134 }), 3135 }; 3136 3137 switch (src.repo_kind) { 3138 inline else => |repo_kind| { 3139 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3140 defer any_repo.deinit(io, allocator); 3141 switch (any_repo) { 3142 inline else => |*repo| try evt.consume(self.session.eventHost(), .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 3143 } 3144 }, 3145 } 3146 3147 // wipe the form so a return visit starts fresh 3148 title_input.clear(allocator); 3149 labels_input.clear(allocator); 3150 description_input.clear(allocator); 3151 3152 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), &event_id_hex) orelse return; 3153 try self.session.navigate(route); 3154 } 3155 3156 // re-emit the selected thread's event with the form's content (status 3157 // preserved), then reload the thread's page. this is the terminal path; 3158 // the web posts the form to the edit route. 3159 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 3160 if (comptime wasm) return; 3161 const io = self.session.io orelse return; 3162 const entry = self.data.selectedThread() orelse return; 3163 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3164 const author = actor.author; 3165 3166 const form = self.threadForm() orelse return; 3167 const title_input = try formField(form, "title"); 3168 const labels_input = try formField(form, "labels"); 3169 const description_input = try formField(form, "description"); 3170 3171 const title = try title_input.text(allocator); 3172 defer allocator.free(title); 3173 const labels = try labels_input.text(allocator); 3174 defer allocator.free(labels); 3175 const description = try description_input.text(allocator); 3176 defer allocator.free(description); 3177 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3178 defer if (comptime supports_drafts) allocator.free(target_branch); 3179 3180 if (!Event.fieldsValid(title, labels)) { 3181 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3182 return; 3183 } 3184 const src = self.data.repo_source orelse return; 3185 3186 if (comptime supports_drafts) { 3187 if (entryDraft(entry.*)) { 3188 self.data.editDraft(self.session, allocator, author, entry.id, title, labels, description, target_branch) catch |err| { 3189 const failure = FeedbackFailure.fromError(err) orelse return err; 3190 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3191 return; 3192 }; 3193 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3194 try self.session.navigate(route); 3195 return; 3196 } 3197 } 3198 3199 const id_bytes = try evt.parseEventId(entry.id); 3200 if (!try src.canModify(io, allocator, actor, kind, &id_bytes)) return; 3201 3202 switch (src.repo_kind) { 3203 inline else => |repo_kind| { 3204 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3205 defer any_repo.deinit(io, allocator); 3206 switch (any_repo) { 3207 inline else => |*repo| if (supports_drafts) { 3208 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3209 .title = title, 3210 .labels = labels, 3211 .description = description, 3212 .target_branch = target_branch, 3213 } }, author) catch |err| { 3214 const failure = FeedbackFailure.fromError(err) orelse return err; 3215 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3216 return; 3217 }; 3218 } else if (has_status) 3219 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3220 .title = title, 3221 .labels = labels, 3222 .description = description, 3223 } }, author) 3224 else 3225 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, labels, description, author), 3226 } 3227 }, 3228 } 3229 3230 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3231 try self.session.navigate(route); 3232 } 3233 3234 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, labels: []const u8, description: []const u8, target_branch: []const u8) !void { 3235 const aa = self.session.arena.allocator(); 3236 const source = if (supports_drafts) blk: { 3237 const form = self.threadForm() orelse break :blk null; 3238 break :blk formWidget(form, .patch_source); 3239 } else null; 3240 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 3241 .failure = failure, 3242 .fields = if (comptime supports_drafts) .{ 3243 .title = try aa.dupe(u8, title), 3244 .labels = try aa.dupe(u8, labels), 3245 .description = try aa.dupe(u8, description), 3246 .target_branch = try aa.dupe(u8, target_branch), 3247 .source_branch = if (source) |value| try value.field().text(aa) else "", 3248 .source_kind = if (source) |value| value.selectedKind() else .fork, 3249 } else .{ 3250 .title = try aa.dupe(u8, title), 3251 .labels = try aa.dupe(u8, labels), 3252 .description = try aa.dupe(u8, description), 3253 }, 3254 }); 3255 } 3256 3257 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3258 switch (confirmation(self.data.view) orelse return) { 3259 .publish => if (comptime supports_drafts) { 3260 if (comptime wasm) return; 3261 const entry = self.data.selectedThread() orelse return; 3262 if (!entryDraft(entry.*)) return; 3263 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3264 try self.data.publishDraft(self.session, allocator, author, entry.id); 3265 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), entry.id) orelse return; 3266 try self.session.navigate(route); 3267 } else unreachable, 3268 .merge => if (comptime supports_merge) { 3269 if (comptime wasm) return; 3270 const entry = self.data.selectedThread() orelse return; 3271 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3272 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3273 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3274 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3275 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3276 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3277 try self.session.navigate(route); 3278 return; 3279 }, 3280 else => return err, 3281 }; 3282 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3283 const route = listRoute(self.data.identity, merged, entry.id) orelse return; 3284 try self.session.navigate(route); 3285 } else unreachable, 3286 .remove => try self.submitRemove(allocator), 3287 } 3288 } 3289 3290 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3291 const attachment_id = self.session.data.current_page.threadAttachment(); 3292 if (attachment_id.len != 0) return self.removeEvent(allocator, .attach, evt.parseEventId(attachment_id) catch return); 3293 const comment = self.data.comment_id.len != 0; 3294 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3295 const id = evt.parseEventId(event_id) catch return; 3296 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3297 } 3298 3299 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3300 if (comptime wasm) return; 3301 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3302 const author = actor.author; 3303 3304 if (comptime supports_drafts) { 3305 const selected = self.data.selectedThread() orelse return; 3306 if (event_kind == kind and entryDraft(selected.*)) { 3307 try Data.removeDraft(self.session, allocator, author, &id); 3308 const route = draftsRoute(self.data.identity) orelse return; 3309 try self.session.navigate(route); 3310 return; 3311 } 3312 } 3313 3314 const io = self.session.io orelse return; 3315 const src = self.data.repo_source orelse return; 3316 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3317 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3318 3319 switch (src.repo_kind) { 3320 inline else => |repo_kind| { 3321 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3322 defer any_repo.deinit(io, allocator); 3323 switch (any_repo) { 3324 inline else => |*repo| try evt.removeInThread(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, event_kind, &id, author), 3325 } 3326 }, 3327 } 3328 3329 // back to the thread, or to its list when the thread itself was removed 3330 const selected = self.data.selectedThread() orelse return; 3331 const route = listRoute(self.data.identity, entryStatus(selected.*), if (event_kind == kind) "" else self.data.selected_id) orelse return; 3332 try self.session.navigate(route); 3333 } 3334 3335 // enter the detail pane, landing on the way back to the list when it shows 3336 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 3337 if (widget.listBackId(self.detailFrame(index)) != null) return widget.focusListBack(self.detailFrame(index), root_focus); 3338 _ = self.detail(index).focusFirst(root_focus); 3339 } 3340 3341 // return to the list. 3342 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3343 root_focus.setFocus(self.listScroll(index).getFocus().id); 3344 } 3345 3346 // cross to the header tabs above the stack. 3347 fn focusHeader(self: *This, root_focus: *Focus) void { 3348 root_focus.setFocus(self.box.children.keys()[header_index]); 3349 } 3350 3351 pub fn clearGrid(self: *This) void { 3352 self.box.clearGrid(); 3353 } 3354 3355 pub fn getGrid(self: This) ?Grid { 3356 return self.box.getGrid(); 3357 } 3358 3359 pub fn getFocus(self: *This) *Focus { 3360 return self.box.getFocus(); 3361 } 3362 3363 // for the parent's "scroll up at the top jumps to the header" check: at the 3364 // top only while the header tabs hold focus, so up from the split 3365 // crosses into the tabs first. 3366 pub fn atTop(self: *This) bool { 3367 return self.headerActive(); 3368 } 3369 }; 3370 } 3371