╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Threads.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
126 } 127 128 fn removeRoute(identity: []const u8, thread_id: []const u8, comment_id: []const u8) ?ui.RoutablePage { 129 return ui.RoutablePage.repoThreadRemoveRoute(kind, identity, thread_id, comment_id); 130 } 131 132 fn editRoute(identity: []const u8, selected: []const u8) ?ui.RoutablePage { 133 return ui.RoutablePage.repoThreadEditRoute(kind, identity, selected); 134 } 135 136 fn newRoute(identity: []const u8) ?ui.RoutablePage { 137 return ui.RoutablePage.repoThreadNewRoute(kind, identity); 138 } 139 140 fn descriptionRoute(identity: []const u8, selected: []const u8) ?ui.RoutablePage { 141 return ui.RoutablePage.repoThreadDescriptionRoute(kind, identity, selected); 142 } 143 144 fn tagsRoute(identity: []const u8, tag: []const u8) ?ui.RoutablePage { 145 return ui.RoutablePage.repoThreadTagsRoute(kind, identity, tag); 146 } 147 148 fn conflictsRoute(identity: []const u8, selected: []const u8) ?ui.RoutablePage { 149 return switch (kind) { 150 .issue => ui.RoutablePage.repoIssuesConflictsRoute(identity, selected), 151 else => @compileError("thread event kind has no conflict route"), 152 }; 153 } 154 155 fn resolveRoute(identity: []const u8, selected: []const u8, picks: []const u8) ?ui.RoutablePage { 156 return switch (kind) { 157 .issue => ui.RoutablePage.repoIssuesResolveRoute(identity, selected, picks), 158 else => @compileError("thread event kind has no resolve route"), 159 }; 160 } 161 162 fn listLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: Status, tag: []const u8, id: []const u8) ![]const u8 { 163 const route = listRoute(identity, status, tag, id) orelse return error.RouteTooLong; 164 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.toUrl(page_arena)}); 165 } 166 167 fn rowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 168 const route = listRoute(identity, @enumFromInt(0), "", id) orelse return error.RouteTooLong; 169 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 170 } 171 172 fn windowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, status_maybe: ?Status, id: []const u8) ![]const u8 { 173 if (has_conflicts and status_maybe == null) { 174 const route = conflictsRoute(data.identity, id) orelse return error.RouteTooLong; 175 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.toUrl(page_arena)}); 176 } 177 return listLink(page_arena, data.identity, status_maybe orelse @enumFromInt(0), data.tag, id); 178 } 179 180 fn descriptionLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 181 const route = descriptionRoute(identity, id) orelse return error.RouteTooLong; 182 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.toUrl(page_arena)}); 183 } 184 185 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: Status, tag: []const u8) ![]const u8 { 186 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 187 return listLink(page_arena, identity, status, encoded, ""); 188 } 189 190 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !This { 191 var outer = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 192 errdefer outer.deinit(allocator); 193 194 // the tabs at the top. 195 { 196 var hdr = try Header.init(allocator, session, data); 197 errdefer hdr.deinit(allocator); 198 switch (kind) { 199 .issue => try outer.children.put(allocator, hdr.getFocus().id, .{ .widget = .{ .repo_issues_header = hdr }, .rect = null, .min_size = null }), 200 .discuss => try outer.children.put(allocator, hdr.getFocus().id, .{ .widget = .{ .repo_discussions_header = hdr }, .rect = null, .min_size = null }), 201 else => @compileError("unsupported thread event kind"), 202 } 203 } 204 205 // the stack enters `outer` before its children enter it, so an error 206 // frees each child exactly once. 207 { 208 var stack = try wgt.Stack(ui.Widget).init(allocator); 209 errdefer stack.deinit(allocator); 210 try outer.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 211 } 212 const stack = &outer.children.values()[stack_index].widget.stack; 213 214 inline for (@typeInfo(Status).@"enum".fields) |field| { 215 var split = try initSplit(allocator, session, data, @enumFromInt(field.value)); 216 errdefer split.deinit(allocator); 217 try stack.children.put(allocator, split.getFocus().id, .{ .box = split }); 218 } 219 220 // the tags view 221 { 222 var tf = try ui.TagFlow.init(allocator); 223 errdefer tf.deinit(allocator); 224 var items: std.ArrayList(ui.TagFlow.Item) = .empty; 225 defer items.deinit(allocator); 226 // when filtered, the first item clears the filter 227 if (data.tag.len != 0) 228 try items.append(allocator, .{ .text = "✕", .link = try listLink(session.page_arena, data.identity, @enumFromInt(0), "", "") }); 229 for (data.tags) |tag| 230 try items.append(allocator, .{ .text = tag, .link = try tagLink(session.page_arena, data.identity, @enumFromInt(0), tag) }); 231 try tf.setItems(allocator, items.items); 232 try stack.children.put(allocator, tf.getFocus().id, .{ .tag_flow = tf }); 233 } 234 235 // the new-issue form, or — on an edit, comment, or resolve url — that form in 236 // its place, prefilled with the selected issue's content. a 237 // logged-out session can't create events, so the unauthorized view 238 // stands in. 239 if (session.data.is_local or session.data.user_id != null) { 240 if (data.view == .remove) { 241 const aa = session.page_arena.allocator(); 242 const route = removeRoute(data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong; 243 const action = try std.fmt.allocPrint(aa, "form:{s}", .{try route.toUrl(session.page_arena)}); 244 const event_name = if (data.comment_id.len == 0) thread_name else "comment"; 245 const label = try std.fmt.allocPrint(aa, "remove {s}", .{event_name}); 246 var center = try initRemoveForm(allocator, action, label); 247 errdefer center.deinit(allocator); 248 try stack.children.put(allocator, center.getFocus().id, .{ .center = center }); 249 } else if (data.view == .new_comment or data.view == .edit_comment) { 250 const editing = data.view == .edit_comment; 251 const route = if (editing) 252 editCommentRoute(data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong 253 else 254 newCommentRoute(data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong; 255 const page_url = try route.toUrl(session.page_arena); 256 const action = try std.fmt.allocPrint(session.page_arena.allocator(), "form:{s}", .{page_url}); 257 const page = data.comment_page; 258 const top_level = if (page) |p| std.mem.eql(u8, &p.selected.comment.event.parent_id, &p.selected.comment.event.thread_id) else false; 259 const parent_route = if (editing) 260 if (top_level) 261 commentsRoute(data.identity, data.selected_id, 0) 262 else if (page) |p| 263 commentRoute(data.identity, data.selected_id, &p.selected.comment.event.parent_id, 0) 264 else 265 null 266 else if (page) |p| 267 commentRoute(data.identity, data.selected_id, &p.selected.id, 0) 268 else 269 commentsRoute(data.identity, data.selected_id, 0); 270 const parent_author: ui.Author = if (editing) 271 if (top_level) 272 if (data.selectedThread()) |entry| entry.author else .unknown 273 else if (page) |p| 274 p.selected.parent_author orelse .unknown 275 else 276 .unknown 277 else if (page) |p| 278 p.selected.author 279 else if (data.selectedThread()) |entry| 280 entry.author 281 else 282 .unknown; 283 const initial_body: ?[]const u8 = if (editing) if (page) |p| p.selected.comment.event.body else null else null; 284 var form = try initCommentForm(allocator, session, action, parent_author, parent_route orelse return error.RouteTooLong, initial_body); 285 errdefer form.deinit(allocator); 286 try stack.children.put(allocator, form.getFocus().id, .{ .box = form }); 287 } else if (has_conflicts and data.view == .resolve) { 288 // on the web the page grows to the form's height and the 289 // browser scrolls it; the terminal scrolls the form itself 290 var form_widget: ui.Widget = blk: { 291 var form = try initResolveForm(allocator, session, data); 292 errdefer form.deinit(allocator); 293 break :blk if (session.is_terminal) 294 .{ .scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = form }, .{ .direction = .vert }) } 295 else 296 .{ .box = form }; 297 }; 298 errdefer form_widget.deinit(allocator); 299 try stack.children.put(allocator, form_widget.getFocus().id, form_widget); 300 } else { 301 const aa = session.page_arena.allocator(); 302 const route = if (data.view == .edit) 303 editRoute(data.identity, data.selected_id) orelse return error.RouteTooLong 304 else 305 newRoute(data.identity) orelse return error.RouteTooLong; 306 const action = try std.fmt.allocPrint(aa, "form:{s}", .{try route.toUrl(session.page_arena)}); 307 const record = if (data.view == .edit) 308 (if (data.selectedThread()) |entry| &entry.record else null) 309 else 310 null; 311 var form = try initThreadForm(allocator, session, action, record); 312 errdefer form.deinit(allocator); 313 try stack.children.put(allocator, form.getFocus().id, .{ .box = form }); 314 } 315 } else { 316 var message = try ui.Unauthorized.View.init(allocator); 317 errdefer message.deinit(allocator); 318 try stack.children.put(allocator, message.getFocus().id, .{ .unauthorized = message }); 319 } 320 321 // the conflicts split; its tab exists only when the repo has 322 // conflicts, so skip the child too to keep the stack 1:1 with the 323 // tabs. 324 if (has_conflicts and data.conflicts.count > 0) { 325 var split = try initSplit(allocator, session, data, null); 326 errdefer split.deinit(allocator); 327 try stack.children.put(allocator, split.getFocus().id, .{ .box = split }); 328 } 329 330 // the stack starts on the page's view. 331 stack.getFocus().child_id = stack.children.keys()[viewIndex(data.view)]; 332 333 // focus entering the view lands on the tabs first. 334 outer.getFocus().child_id = outer.children.keys()[header_index]; 335 336 return .{ 337 .box = outer, 338 .data = data, 339 .session = session, 340 .detailed_index = @splat(null), 341 .description_id = @splat(null), 342 .author_id = @splat(null), 343 .status_button_id = @splat(null), 344 }; 345 } 346 347 // the master-detail split showing `status`'s window, or the conflicts 348 // window when null. 349 fn initSplit(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self, status_maybe: ?Status) !wgt.Box(ui.Widget) { 350 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 351 errdefer box.deinit(allocator); 352 353 const win = if (status_maybe) |status| data.window(status) else if (has_conflicts) &data.conflicts else unreachable; 354 355 // the issue list (one focusable row per title), plus a "next" link that 356 // reloads the page rooted at the following issue. 357 { 358 var list_scroll = blk: { 359 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert, .stretch = true }); 360 errdefer list_box.deinit(allocator); 361 if (win.prev_id) |prev| 362 try addRow(allocator, &list_box, "← previous", "", try windowLink(session.page_arena, data, status_maybe, prev)); 363 for (win.items) |entry| { 364 // conflicts take precedence over the comment count 365 const label: []const u8 = if (entryConflicted(entry) and status_maybe != null) 366 " conflict " 367 else if (entry.comments.count > 0) 368 try std.fmt.allocPrint(session.page_arena.allocator(), " {d} comments ", .{entry.comments.count}) 369 else 370 ""; 371 try addRow(allocator, &list_box, entry.record.event.title, label, try rowLink(session.page_arena, data.identity, entry.id)); 372 } 373 if (win.next_id) |next| 374 try addRow(allocator, &list_box, "next →", "", try windowLink(session.page_arena, data, status_maybe, next)); 375 // select the window's first issue (past a leading "previous" 376 // row) so its description shows on load. 377 if (win.items.len > 0) 378 list_box.getFocus().child_id = list_box.children.keys()[if (win.prev_id != null) 1 else 0] 379 else if (list_box.children.count() > 0) 380 list_box.getFocus().child_id = list_box.children.keys()[0]; 381 break :blk try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal }); 382 }; 383 errdefer list_scroll.deinit(allocator); 384 try box.children.put(allocator, list_scroll.getFocus().id, .{ .widget = .{ .scroll = list_scroll }, .rect = null, .min_size = .{ .width = list_max_width, .height = null }, .max_size = .{ .width = list_max_width, .height = null } }); 385 } 386 387 // the detail pane — a frame around a scroll of the description 388 { 389 var detail_outer = blk: { 390 var detail_scroll = blk2: { 391 var detail_inner = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 392 errdefer detail_inner.deinit(allocator); 393 // fill the pane (content top-left, scroll bar pinned to the 394 // edge) rather than shrinking to the description. 395 break :blk2 try wgt.Scroll(ui.Widget).init(allocator, .{ .box = detail_inner }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 396 }; 397 errdefer detail_scroll.deinit(allocator); 398 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .hidden, .direction = .vert }); 399 errdefer frame.deinit(allocator); 400 // the tool row sits above the scroll (populateDetail fills 401 // it per issue) so it can't scroll out from under the web 402 // overlay <form>, whose position doesn't track pane scrolling. 403 { 404 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 405 errdefer row.deinit(allocator); 406 try frame.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 407 } 408 // the frame's selected child is its scroll, so the focus chain 409 // reaches the description (populateDetail points the scroll's 410 // inner box at it), letting focus recovery descend into the pane. 411 frame.getFocus().child_id = detail_scroll.getFocus().id; 412 try frame.children.put(allocator, detail_scroll.getFocus().id, .{ .widget = .{ .scroll = detail_scroll }, .rect = null, .min_size = null }); 413 break :blk frame; 414 }; 415 errdefer detail_outer.deinit(allocator); 416 try box.children.put(allocator, detail_outer.getFocus().id, .{ .widget = .{ .box = detail_outer }, .rect = null, .min_size = .{ .width = detail_min_width, .height = null } }); 417 } 418 419 box.getFocus().child_id = box.children.keys()[list_index]; 420 return box; 421 } 422 423 // a thread form: title/tags/description inputs and a submit button, 424 // prefilled from `record` when given. its form: subtree makes the web 425 // overlay wrap them in a <form> POSTing to `action`'s route. 426 fn initThreadForm(allocator: std.mem.Allocator, session: *ui.Session, action: []const u8, record: ?*const Event.Record) !wgt.Box(ui.Widget) { 427 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 428 errdefer box.deinit(allocator); 429 box.getFocus().kind = .{ .custom = action }; 430 431 { 432 var title = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " title ", .name = "title", .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal }); 433 errdefer title.deinit(allocator); 434 title.getFocus().focusable = true; 435 if (record) |r| try title.setContent(allocator, r.event.title); 436 try box.children.put(allocator, title.getFocus().id, .{ .widget = .{ .text_input = title }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 437 } 438 439 { 440 var tags = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " tags (separate with spaces) ", .name = "tags", .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal }); 441 errdefer tags.deinit(allocator); 442 tags.getFocus().focusable = true; 443 if (record) |r| try tags.setContent(allocator, r.event.tags); 444 try box.children.put(allocator, tags.getFocus().id, .{ .widget = .{ .text_input = tags }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 445 } 446 447 { 448 var description = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " description ", .name = "description", .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal, .multiline = true, .scroll = .{ .fill = true } }); 449 errdefer description.deinit(allocator); 450 description.getFocus().focusable = true; 451 if (record) |r| try description.setContent(allocator, r.event.description); 452 try box.children.put(allocator, description.getFocus().id, .{ .widget = .{ .text_input = description }, .rect = null, .min_size = null }); 453 } 454 455 try addSubmitButton(allocator, &box); 456 457 box.getFocus().child_id = box.children.keys()[title_field_index]; 458 return box; 459 } 460 461 fn initCommentForm(allocator: std.mem.Allocator, session: *ui.Session, action: []const u8, author: ui.Author, parent_route: ui.RoutablePage, initial_body: ?[]const u8) !wgt.Box(ui.Widget) { 462 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 463 errdefer box.deinit(allocator); 464 box.getFocus().kind = .{ .custom = action }; 465 466 { 467 var parent = try ui.authorBox(allocator, session.page_arena, author); 468 errdefer parent.deinit(allocator); 469 parent.options.label = " replying to "; 470 parent.getFocus().kind = .{ .custom = try std.fmt.allocPrint(session.page_arena.allocator(), "a:{s}", .{try parent_route.toUrl(session.page_arena)}) }; 471 try box.children.put(allocator, parent.getFocus().id, .{ .widget = .{ .text_box = parent }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 472 } 473 474 { 475 var body = try wgt.TextInput(ui.Widget).init(allocator, .{ 476 .label = " comment ", 477 .name = "body", 478 .visible_width = null, 479 .rounded_corners = true, 480 .render_content = session.is_terminal, 481 .multiline = true, 482 .visible_height = 5, 483 .scroll = .{ .fill = true }, 484 }); 485 errdefer body.deinit(allocator); 486 body.getFocus().focusable = true; 487 if (initial_body) |text| try body.setContent(allocator, text); 488 try box.children.put(allocator, body.getFocus().id, .{ .widget = .{ .text_input = body }, .rect = null, .min_size = null }); 489 } 490 491 try addSubmitButtonLabeled(allocator, &box, "submit"); 492 box.getFocus().child_id = box.children.keys()[comment_author_field_index]; 493 return box; 494 } 495 496 fn initRemoveForm(allocator: std.mem.Allocator, action: []const u8, label: []const u8) !ui.Center { 497 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .rounded_corners = true, .direction = .vert }); 498 errdefer box.deinit(allocator); 499 box.getFocus().kind = .{ .custom = action }; 500 501 var prompt = try wgt.Text(ui.Widget).init(allocator, "are you sure?"); 502 errdefer prompt.deinit(allocator); 503 try box.children.put(allocator, prompt.getFocus().id, .{ .widget = .{ .text = prompt }, .rect = null, .min_size = null }); 504 505 var button = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 506 errdefer button.deinit(allocator); 507 button.getFocus().focusable = true; 508 button.getFocus().kind = .{ .custom = "submit" }; 509 try box.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = null }); 510 box.getFocus().child_id = button.getFocus().id; 511 512 return ui.Center.init(allocator, .{ .box = box }); 513 } 514 515 // a form's submit button, then a spacer absorbing the leftover 516 // min-height the box hands its last child, so the button keeps its 517 // natural height 518 fn addSubmitButton(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget)) !void { 519 return addSubmitButtonLabeled(allocator, box, "submit"); 520 } 521 522 fn addSubmitButtonLabeled(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8) !void { 523 { 524 var submit = try ui.SubmitButton.initLabeled(allocator, label); 525 errdefer submit.deinit(allocator); 526 try box.children.put(allocator, submit.getFocus().id, .{ .widget = .{ .submit_button = submit }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 527 } 528 { 529 var spacer = try ui.Spacer.init(allocator); 530 errdefer spacer.deinit(allocator); 531 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 532 } 533 } 534 535 // the conflict resolve form. the "use this" links are navigations that 536 // flip the url's theirs: pick, reloading the prefills; one submit 537 // settles every conflict. the form: subtree makes the web overlay POST 538 // to the resolve route. 539 fn initResolveForm(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !wgt.Box(ui.Widget) { 540 const aa = session.page_arena.allocator(); 541 // init only picks the resolve view once it has read the conflict 542 const conflict = if (data.conflict) |*c| c else unreachable; 543 544 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 545 errdefer box.deinit(allocator); 546 const route = resolveRoute(data.identity, data.selected_id, "") orelse return error.RouteTooLong; 547 box.getFocus().kind = .{ .custom = try std.fmt.allocPrint(aa, "form:{s}", .{try route.toUrl(session.page_arena)}) }; 548 549 if (conflict.title) |*fc| { 550 try addLabel(allocator, &box, "title conflict:"); 551 try addFieldConflict(allocator, &box, session, data, "title", fc); 552 } 553 if (conflict.tags) |*fc| { 554 try addLabel(allocator, &box, "tags conflict:"); 555 try addFieldConflict(allocator, &box, session, data, "tags", fc); 556 } 557 558 if (conflict.description) |*desc| { 559 try addLabel(allocator, &box, "description conflict:"); 560 var hunk_index: usize = 0; 561 for (desc.chunks, 0..) |*chunk, chunk_index| { 562 switch (chunk.*) { 563 .same => |text| { 564 var tb = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word }); 565 errdefer tb.deinit(allocator); 566 tb.getFocus().focusable = true; 567 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 568 }, 569 // an auto-resolved chunk: only one side changed it, so its 570 // version stands, shown distinctly with its author 571 .auto => |auto| { 572 const author = if (auto.theirs) desc.theirs_author else desc.ours_author; 573 const verb: []const u8 = if (auto.text == null) "removed" else "edited"; 574 const label = switch (author) { 575 .user_name, .email => |name| try std.fmt.allocPrint(aa, " {s} by {s} ", .{ verb, name }), 576 .unknown => try std.fmt.allocPrint(aa, " {s} by {s} ", .{ verb, if (auto.theirs) @as([]const u8, "them") else "us" }), 577 }; 578 var tb = try wgt.TextBox(ui.Widget).init(allocator, auto.text orelse "(removed)", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word, .label = label }); 579 errdefer tb.deinit(allocator); 580 tb.getFocus().focusable = true; 581 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 582 }, 583 .conflict => |hunk| { 584 // a blank row on each side sets the group apart from 585 // the flowing shared and auto-resolved chunks 586 if (chunk_index > 0) try addGap(allocator, &box); 587 const name = try std.fmt.allocPrint(aa, "d{d}", .{hunk_index}); 588 hunk_index += 1; 589 const picked_theirs = data.theirsPicked(name); 590 try addVersionRow(allocator, &box, try sideLabel(aa, desc.ours_author, true), hunk.ours orelse "", try useThisLink(session, data, name, false)); 591 try addVersionRow(allocator, &box, try sideLabel(aa, desc.theirs_author, false), hunk.theirs orelse "", try useThisLink(session, data, name, true)); 592 var resolution_input = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " resolution ", .name = name, .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal, .multiline = true }); 593 errdefer resolution_input.deinit(allocator); 594 resolution_input.getFocus().focusable = true; 595 try resolution_input.setContent(allocator, (if (picked_theirs) hunk.theirs else hunk.ours) orelse ""); 596 try box.children.put(allocator, resolution_input.getFocus().id, .{ .widget = .{ .text_input = resolution_input }, .rect = null, .min_size = null }); 597 if (chunk_index + 1 < desc.chunks.len) try addGap(allocator, &box); 598 }, 599 } 600 } 601 } 602 603 try addSubmitButton(allocator, &box); 604 605 box.getFocus().child_id = box.children.keys()[0]; 606 return box; 607 } 608 609 // one conflicted scalar field: both sides' version rows, then the 610 // resolution input prefilled from the picked side. 611 fn addFieldConflict(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), session: *ui.Session, data: *const Self, comptime name: []const u8, fc: *const FieldConflict) !void { 612 const aa = session.page_arena.allocator(); 613 try addVersionRow(allocator, box, try sideLabel(aa, fc.ours.author, true), fc.ours.text, try useThisLink(session, data, name, false)); 614 try addVersionRow(allocator, box, try sideLabel(aa, fc.theirs.author, false), fc.theirs.text, try useThisLink(session, data, name, true)); 615 616 var resolution_input = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " resolution ", .name = name, .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal }); 617 errdefer resolution_input.deinit(allocator); 618 resolution_input.getFocus().focusable = true; 619 try resolution_input.setContent(allocator, if (data.theirsPicked(name)) fc.theirs.text else fc.ours.text); 620 try box.children.put(allocator, resolution_input.getFocus().id, .{ .widget = .{ .text_input = resolution_input }, .rect = null, .min_size = null }); 621 } 622 623 // a blank row setting a conflict group apart from its neighbors 624 fn addGap(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget)) !void { 625 var text = try wgt.Text(ui.Widget).init(allocator, " "); 626 errdefer text.deinit(allocator); 627 try box.children.put(allocator, text.getFocus().id, .{ .widget = .{ .text = text }, .rect = null, .min_size = null }); 628 } 629 630 fn addLabel(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), content: []const u8) !void { 631 var label = try ui.SectionLabel.init(allocator, content); 632 errdefer label.deinit(allocator); 633 try box.children.put(allocator, label.getFocus().id, .{ .widget = .{ .section_label = label }, .rect = null, .min_size = null }); 634 } 635 636 // one side of a conflict: the "use this" link on the left, the version 637 // itself as a labeled read-only box. 638 fn addVersionRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, text: []const u8, link: []const u8) !void { 639 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 640 errdefer row.deinit(allocator); 641 642 { 643 const use_label = "use this"; 644 var use = try wgt.TextBox(ui.Widget).init(allocator, use_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 645 errdefer use.deinit(allocator); 646 use.getFocus().focusable = true; 647 use.getFocus().kind = .{ .custom = link }; 648 try row.children.put(allocator, use.getFocus().id, .{ 649 .widget = .{ .text_box = use }, 650 .rect = null, 651 .min_size = .{ .width = use_label.len + 2, .height = null }, 652 .max_size = .{ .width = use_label.len + 2, .height = null }, 653 }); 654 } 655 656 { 657 var tb = try wgt.TextBox(ui.Widget).init(allocator, if (text.len > 0) text else "(removed)", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word, .label = label }); 658 errdefer tb.deinit(allocator); 659 tb.getFocus().focusable = true; 660 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 661 } 662 663 row.getFocus().child_id = row.children.keys()[0]; 664 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 665 } 666 667 // the label of one side's version box, naming its author 668 fn sideLabel(aa: std.mem.Allocator, author: ui.Author, ours: bool) ![]const u8 { 669 return switch (author) { 670 .user_name, .email => |name| try std.fmt.allocPrint(aa, " edited by {s} ", .{name}), 671 .unknown => if (ours) " current version " else " their version ", 672 }; 673 } 674 675 // the a: link that reloads the resolve page with `name` picked from ours 676 // or theirs, reprefilling its resolution input 677 fn useThisLink(session: *ui.Session, data: *const Self, name: []const u8, theirs: bool) ![]const u8 { 678 const aa = session.page_arena.allocator(); 679 var picks: std.ArrayList(u8) = .empty; 680 var it = std.mem.splitScalar(u8, data.theirs_picks, ','); 681 while (it.next()) |pick| { 682 if (pick.len == 0 or std.mem.eql(u8, pick, name)) continue; 683 if (picks.items.len > 0) try picks.append(aa, ','); 684 try picks.appendSlice(aa, pick); 685 } 686 if (theirs) { 687 if (picks.items.len > 0) try picks.append(aa, ','); 688 try picks.appendSlice(aa, name); 689 } 690 const route = resolveRoute(data.identity, data.selected_id, picks.items) orelse return error.RouteTooLong; 691 return std.fmt.allocPrint(aa, "a:{s}", .{try route.toUrl(session.page_arena)}); 692 } 693 694 // the resolve form's page-constant initial value for the input `name`: 695 // the picked side of its conflicted field or hunk 696 fn resolvePrefill(self: *This, name: []const u8) ?[]const u8 { 697 const conflict = if (self.data.conflict) |*c| c else return null; 698 const theirs = self.data.theirsPicked(name); 699 if (std.mem.eql(u8, name, "title")) { 700 const fc = if (conflict.title) |*f| f else return null; 701 return if (theirs) fc.theirs.text else fc.ours.text; 702 } 703 if (std.mem.eql(u8, name, "tags")) { 704 const fc = if (conflict.tags) |*f| f else return null; 705 return if (theirs) fc.theirs.text else fc.ours.text; 706 } 707 if (std.mem.startsWith(u8, name, "d")) { 708 const desc = if (conflict.description) |*d| d else return null; 709 const hunk_index = std.fmt.parseInt(usize, name[1..], 10) catch return null; 710 var seen: usize = 0; 711 for (desc.chunks) |chunk| switch (chunk) { 712 .conflict => |hunk| { 713 if (seen == hunk_index) return (if (theirs) hunk.theirs else hunk.ours) orelse ""; 714 seen += 1; 715 }, 716 else => {}, 717 }; 718 } 719 return null; 720 } 721 722 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), text: []const u8, bottom_label: []const u8, link: []const u8) !void { 723 var row = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .word, .bottom_label = bottom_label }); 724 errdefer row.deinit(allocator); 725 row.getFocus().focusable = true; 726 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 727 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 728 } 729 730 pub fn deinit(self: *This, allocator: std.mem.Allocator) void { 731 self.box.deinit(allocator); 732 } 733 734 fn header(self: *This) *Header { 735 return switch (kind) { 736 .issue => &self.box.children.values()[header_index].widget.repo_issues_header, 737 .discuss => &self.box.children.values()[header_index].widget.repo_discussions_header, 738 else => @compileError("unsupported thread event kind"), 739 }; 740 } 741 742 fn viewStack(self: *This) *wgt.Stack(ui.Widget) { 743 return &self.box.children.values()[stack_index].widget.stack; 744 } 745 746 // `index`'s master-detail split inside the stack. 747 fn resultsBox(self: *This, index: usize) *wgt.Box(ui.Widget) { 748 return &self.viewStack().children.values()[index].box; 749 } 750 751 // the tags view's flow inside the stack. 752 fn tagsView(self: *This) *ui.TagFlow { 753 return &self.viewStack().children.values()[tags_view_index].tag_flow; 754 } 755 756 // the new-issue, edit, or resolve form inside the stack, or null when the 757 // unauthorized view stands in for it. 758 fn threadForm(self: *This) ?*wgt.Box(ui.Widget) { 759 return switch (self.viewStack().children.values()[form_view_index]) { 760 .box => |*box| box, 761 // the resolve form sits inside a scroll on the terminal 762 .scroll => |*scroll| &scroll.child.box, 763 else => null, 764 }; 765 } 766 767 fn removeForm(self: *This) ?*wgt.Box(ui.Widget) { 768 return switch (self.viewStack().children.values()[form_view_index]) { 769 .center => |*center| switch (center.child.*) { 770 .box => |*box| box, 771 else => null, 772 }, 773 else => null, 774 }; 775 } 776 777 // the resolve form's scroll on the terminal (the web page scrolls itself) 778 fn resolveScroll(self: *This) ?*wgt.Scroll(ui.Widget) { 779 return switch (self.viewStack().children.values()[form_view_index]) { 780 .scroll => |*scroll| scroll, 781 else => null, 782 }; 783 } 784 785 fn listScroll(self: *This, index: usize) *wgt.Scroll(ui.Widget) { 786 return &self.resultsBox(index).children.values()[list_index].widget.scroll; 787 } 788 789 fn listBox(self: *This, index: usize) *wgt.Box(ui.Widget) { 790 return &self.listScroll(index).child.box; 791 } 792 793 // the detail frame's children: the tool row above the scroll pane. 794 const tool_row_index: usize = 0; 795 const detail_scroll_index: usize = 1; 796 797 fn detailOuter(self: *This, index: usize) *wgt.Box(ui.Widget) { 798 return &self.resultsBox(index).children.values()[detail_index].widget.box; 799 } 800 801 fn toolRow(self: *This, index: usize) *wgt.Box(ui.Widget) { 802 return &self.detailOuter(index).children.values()[tool_row_index].widget.box; 803 } 804 805 fn detailScroll(self: *This, index: usize) *wgt.Scroll(ui.Widget) { 806 return &self.detailOuter(index).children.values()[detail_scroll_index].widget.scroll; 807 } 808 809 fn detailInner(self: *This, index: usize) *wgt.Box(ui.Widget) { 810 return &self.detailScroll(index).child.box; 811 } 812 813 fn window(self: *This, index: usize) *const Window { 814 if (has_conflicts and index == conflict_view_index) return &self.data.conflicts; 815 return self.data.window(splitStatus(index)); 816 } 817 818 fn stackSelectedIndex(self: *This) ?usize { 819 const stack = self.viewStack(); 820 const cid = stack.getFocus().child_id orelse return null; 821 return stack.children.getIndex(cid); 822 } 823 824 // the stack's selected master-detail split (null when the tags view or the 825 // new-issue form shows). 826 fn selectedSplitIndex(self: *This) ?usize { 827 const idx = self.stackSelectedIndex() orelse return null; 828 return if (idx < status_count or idx == conflict_view_index) idx else null; 829 } 830 831 fn detailActive(self: *This, index: usize) bool { 832 const rb = self.resultsBox(index); 833 const cid = rb.getFocus().child_id orelse return false; 834 return rb.children.getIndex(cid) == detail_index; 835 } 836 837 fn headerActive(self: *This) bool { 838 const cid = self.box.getFocus().child_id orelse return false; 839 return self.box.children.getIndex(cid) == header_index; 840 } 841 842 fn tagsViewActive(self: *This) bool { 843 if (self.headerActive()) return false; 844 return self.stackSelectedIndex() == tags_view_index; 845 } 846 847 fn formViewActive(self: *This) bool { 848 if (self.headerActive()) return false; 849 return self.stackSelectedIndex() == form_view_index; 850 } 851 852 // the selected issue's index, or null when a window-navigation row is 853 // selected (a leading "previous" row shifts the issue rows down by one). 854 fn selectedThreadIndex(self: *This, index: usize) ?usize { 855 const lb = self.listBox(index); 856 const cid = lb.getFocus().child_id orelse return null; 857 const idx = lb.children.getIndex(cid) orelse return null; 858 const win = self.window(index); 859 const lead: usize = if (win.prev_id != null) 1 else 0; 860 if (idx < lead or idx - lead >= win.items.len) return null; 861 return idx - lead; 862 } 863 864 pub fn build(self: *This, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 865 self.clearGrid(); 866 867 // each header tab maps 1:1 to a stack child by position. mirror the 868 // selection into the url: the view the page's window is rooted at 869 // keeps its rooted url, the others get their list route (keeping the 870 // tag filter). 871 if (self.header().getSelectedIndex()) |index| { 872 const stack = self.viewStack(); 873 stack.getFocus().child_id = stack.children.keys()[index]; 874 self.session.data.current_page = (if (index == form_view_index) 875 (if (has_conflicts) switch (self.data.view) { 876 .edit => editRoute(self.data.identity, self.data.selected_id), 877 .new_comment => newCommentRoute(self.data.identity, self.data.selected_id, self.data.comment_id), 878 .edit_comment => editCommentRoute(self.data.identity, self.data.selected_id, self.data.comment_id), 879 .remove => removeRoute(self.data.identity, self.data.selected_id, self.data.comment_id), 880 .resolve => resolveRoute(self.data.identity, self.data.selected_id, self.data.theirs_picks), 881 else => newRoute(self.data.identity), 882 } else switch (self.data.view) { 883 .edit => editRoute(self.data.identity, self.data.selected_id), 884 .new_comment => newCommentRoute(self.data.identity, self.data.selected_id, self.data.comment_id), 885 .edit_comment => editCommentRoute(self.data.identity, self.data.selected_id, self.data.comment_id), 886 .remove => removeRoute(self.data.identity, self.data.selected_id, self.data.comment_id), 887 else => newRoute(self.data.identity), 888 }) 889 else if (has_conflicts and index == conflict_view_index) 890 conflictsRoute(self.data.identity, if (self.data.view == .conflicts) self.data.selected_id else "") 891 else if (index == viewIndex(self.data.view) and self.data.selected_id.len != 0) 892 (if (self.data.description_page) 893 descriptionRoute(self.data.identity, self.data.selected_id) 894 else if (self.data.comment_page) |page| 895 commentRoute(self.data.identity, self.data.selected_id, &page.selected.id, page.replies.start) 896 else 897 commentsRoute(self.data.identity, self.data.selected_id, self.data.comments_start)) 898 else if (index == tags_view_index) 899 tagsRoute(self.data.identity, self.data.tag) 900 else 901 listRoute(self.data.identity, splitStatus(index), self.data.tag, "")) orelse self.session.data.current_page; 902 } 903 904 if (self.selectedSplitIndex()) |i| { 905 // swap the detail pane to the selected issue when it changes. 906 try self.refreshDetail(allocator, i); 907 908 // mirror the focused issue into the url, but only while focus is 909 // inside the split. an issue's url is the same whether or not the 910 // list is filtered, so the mirror drops the tag. 911 if (root_focus.grandchild_id) |g| { 912 if (self.resultsBox(i).getFocus().children.contains(g)) { 913 if (self.selectedThreadIndex(i)) |sel| { 914 // selecting another issue leaves the description page 915 // behind, like it leaves the tag filter behind. 916 const entry = &self.window(i).items[sel]; 917 const mirrored = if (self.data.description_page and std.mem.eql(u8, entry.id, self.data.selected_id)) 918 descriptionRoute(self.data.identity, entry.id) 919 else if (self.data.comment_page) |page| 920 if (std.mem.eql(u8, entry.id, self.data.selected_id)) 921 commentRoute(self.data.identity, entry.id, &page.selected.id, page.replies.start) 922 else 923 commentsRoute(self.data.identity, entry.id, 0) 924 else if (std.mem.eql(u8, entry.id, self.data.selected_id)) 925 commentsRoute(self.data.identity, entry.id, entry.comments.start) 926 else 927 commentsRoute(self.data.identity, entry.id, 0); 928 if (mirrored) |route| self.session.data.current_page = route; 929 } 930 } 931 } 932 933 // the selected list row shows a border (the focused TextBox 934 // upgrades it to a double border itself); the rest stay borderless. 935 const lb = self.listBox(i); 936 for (lb.children.keys(), lb.children.values()) |id, *child| { 937 switch (child.widget) { 938 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 939 else => {}, 940 } 941 } 942 943 // the pane's selected child shows the selection border: the 944 // description directly, the tags via the flow's selected item. 945 // cap the list at list_max_width only while the detail pane fits 946 // beside it. the box drops the detail when the width can't hold 947 // both minimums, so when it's that narrow we lift the cap and let 948 // the list fill the whole width. 949 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 950 self.resultsBox(i).children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 951 952 // stretch the detail pane across the rest of the width so it fills 953 // the area rather than shrinking to its content; its scroll fills 954 // the pane. 955 if (constraint.max_size.width) |w| { 956 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = if (both_panes_fit) w - list_max_width else w, .height = null }; 957 } else { 958 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 959 } 960 } 961 962 // refresh the form inputs' entries in the session's focus-id -> input 963 // map with this frame's addresses, so the web/wasm form handling can 964 // find them by focus id 965 if (self.threadForm()) |form| { 966 const inputs_arena = self.session.arena.allocator(); 967 for (form.children.values()) |*child| switch (child.widget) { 968 .text_input => |*ti| try self.session.text_inputs.put(inputs_arena, ti.getFocus().id, ti), 969 else => {}, 970 }; 971 972 // on an edit page, register the issue's content as the inputs' 973 // page-constant initial values, which the web overlay renders 974 // into them. 975 if (self.data.view == .edit) { 976 if (self.data.selectedThread()) |entry| { 977 const fields = form.children.values(); 978 try self.session.input_values.put(inputs_arena, fields[title_field_index].widget.text_input.getFocus().id, entry.record.event.title); 979 try self.session.input_values.put(inputs_arena, fields[tags_field_index].widget.text_input.getFocus().id, entry.record.event.tags); 980 try self.session.input_values.put(inputs_arena, fields[description_field_index].widget.text_input.getFocus().id, entry.record.event.description); 981 } 982 } 983 984 if (self.data.view == .edit_comment) { 985 if (self.data.comment_page) |page| { 986 const body = &form.children.values()[comment_body_field_index].widget.text_input; 987 try self.session.input_values.put(inputs_arena, body.getFocus().id, page.selected.comment.event.body); 988 } 989 } 990 991 // the resolve form's inputs prefill from the picked side, which 992 // is url state and so page-constant like the edit values above 993 if (has_conflicts and self.data.view == .resolve) { 994 for (form.children.values()) |*child| switch (child.widget) { 995 .text_input => |*ti| if (self.resolvePrefill(ti.options.name)) |value| { 996 try self.session.input_values.put(inputs_arena, ti.getFocus().id, value); 997 }, 998 else => {}, 999 }; 1000 } 1001 } 1002 1003 try self.box.build(allocator, constraint, root_focus); 1004 } 1005 1006 fn refreshDetail(self: *This, allocator: std.mem.Allocator, index: usize) !void { 1007 const sel = self.selectedThreadIndex(index) orelse return; 1008 if (self.detailed_index[index]) |d| if (d == sel) return; 1009 try self.populateDetail(allocator, index, sel); 1010 self.detailed_index[index] = sel; 1011 } 1012 1013 fn populateDetail(self: *This, allocator: std.mem.Allocator, index: usize, sel: usize) !void { 1014 const entry = self.window(index).items[sel]; 1015 const inner = self.detailInner(index); 1016 // the /description page replaces its issue's detail with a back link 1017 // and the whole description; other issues keep their normal detail. 1018 const description_page = self.data.description_page and std.mem.eql(u8, entry.id, self.data.selected_id); 1019 const comment_page = if (std.mem.eql(u8, entry.id, self.data.selected_id)) self.data.comment_page else null; 1020 1021 for (inner.children.values()) |*child| child.widget.deinit(allocator); 1022 inner.children.clearAndFree(allocator); 1023 inner.getFocus().child_id = null; 1024 self.author_id[index] = null; 1025 self.status_button_id[index] = null; 1026 1027 // the tool row: the open/close and edit buttons; the description page 1028 // shows none. 1029 { 1030 const row = self.toolRow(index); 1031 for (row.children.values()) |*child| child.widget.deinit(allocator); 1032 row.children.clearAndFree(allocator); 1033 row.getFocus().child_id = null; 1034 row.getFocus().kind = .container; 1035 } 1036 if (!description_page and comment_page == null) { 1037 const row = self.toolRow(index); 1038 const pa = self.session.page_arena.allocator(); 1039 1040 { 1041 var spacer = try ui.Spacer.init(allocator); 1042 errdefer spacer.deinit(allocator); 1043 try row.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1044 } 1045 1046 // a terminal has no file picker, so attaching is web only. the 1047 // renderer covers this button with a file input, so clicking it 1048 // opens the browser's own picker and posts what it chose. 1049 if (!self.session.is_terminal and !entryConflicted(entry) and (self.session.data.is_local or self.session.data.user_id != null)) { 1050 const label = "add attachment"; 1051 var button = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1052 errdefer button.deinit(allocator); 1053 button.getFocus().focusable = true; 1054 button.getFocus().kind = .{ .custom = if (self.data.identity.len == 0) 1055 try std.fmt.allocPrint(pa, "{s}/{s}:{s}/attach", .{ ui.file_input_prefix, @tagName(kind), entry.id }) 1056 else 1057 try std.fmt.allocPrint(pa, "{s}/repo/{s}/{s}:{s}/attach", .{ ui.file_input_prefix, self.data.identity, @tagName(kind), entry.id }) }; 1058 try row.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = .{ .width = label.len + 2, .height = null } }); 1059 } 1060 1061 // a conflicted issue's only action is resolving it. the button 1062 // stays visible logged out; the resolve page shows the 1063 // unauthorized view then. 1064 if (has_conflicts and entryConflicted(entry)) { 1065 const label = "resolve conflict"; 1066 var button = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1067 errdefer button.deinit(allocator); 1068 button.getFocus().focusable = true; 1069 const route = resolveRoute(self.data.identity, entry.id, "") orelse return error.RouteTooLong; 1070 button.getFocus().kind = .{ .custom = try std.fmt.allocPrint(pa, "a:{s}", .{try route.toUrl(self.session.page_arena)}) }; 1071 try row.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = .{ .width = label.len + 2, .height = null } }); 1072 } else { 1073 // a logged-out session can't flip the status, so it gets no 1074 // open/close button 1075 if (has_status and (self.session.data.is_local or self.session.data.user_id != null)) { 1076 const action: []const u8 = switch (entryStatus(entry)) { 1077 .open => "close", 1078 .closed => "open", 1079 }; 1080 const route = commentsRoute(self.data.identity, entry.id, 0) orelse return error.RouteTooLong; 1081 row.getFocus().kind = .{ .custom = try std.fmt.allocPrint(pa, "form:{s}/{s}", .{ try route.toUrl(self.session.page_arena), action }) }; 1082 1083 var button = try wgt.TextBox(ui.Widget).init(allocator, action, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1084 errdefer button.deinit(allocator); 1085 button.getFocus().focusable = true; 1086 // the renderer distinguishes plain clickables from buttons 1087 // that should POST to a server route by this kind. 1088 button.getFocus().kind = .{ .custom = "submit" }; 1089 self.status_button_id[index] = button.getFocus().id; 1090 try row.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = .{ .width = action.len + 2, .height = null } }); 1091 } 1092 1093 // the edit button links to the issue's edit page. 1094 { 1095 var button = try wgt.TextBox(ui.Widget).init(allocator, "edit", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1096 errdefer button.deinit(allocator); 1097 button.getFocus().focusable = true; 1098 const route = editRoute(self.data.identity, entry.id) orelse return error.RouteTooLong; 1099 button.getFocus().kind = .{ .custom = try std.fmt.allocPrint(pa, "a:{s}", .{try route.toUrl(self.session.page_arena)}) }; 1100 try row.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = .{ .width = "edit".len + 2, .height = null } }); 1101 } 1102 } 1103 1104 if (self.session.data.is_local or self.session.data.user_id != null) { 1105 var remove = try wgt.TextBox(ui.Widget).init(allocator, "✕", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1106 errdefer remove.deinit(allocator); 1107 remove.getFocus().focusable = true; 1108 const route = removeRoute(self.data.identity, entry.id, "") orelse return error.RouteTooLong; 1109 remove.getFocus().kind = .{ .custom = try std.fmt.allocPrint(pa, "a:{s}", .{try route.toUrl(self.session.page_arena)}) }; 1110 try row.children.put(allocator, remove.getFocus().id, .{ .widget = .{ .text_box = remove }, .rect = null, .min_size = .{ .width = 3, .height = null } }); 1111 } 1112 1113 // the leftmost button: the attachment button when the session has 1114 // one, else the resolve button on a conflicted issue, the 1115 // open/close button when present, the edit button otherwise 1116 row.getFocus().child_id = row.children.keys()[first_in_row_index]; 1117 } 1118 1119 if (comment_page) |page| { 1120 const back_label = try std.fmt.allocPrint(self.session.page_arena.allocator(), "← back to {s}", .{thread_name}); 1121 var back = try Comment.linkBox(allocator, self.session, back_label, commentsRoute(self.data.identity, entry.id, 0) orelse return error.RouteTooLong); 1122 errdefer back.deinit(allocator); 1123 try inner.children.put(allocator, back.getFocus().id, .{ .widget = .{ .text_box = back }, .rect = null, .min_size = null }); 1124 1125 try Comment.appendComment(allocator, inner, self.session, self.data.identity, kind, page.selected); 1126 try Comment.appendCount(allocator, inner, page.replies.count, "reply", "replies", self.session.page_arena.allocator()); 1127 for (page.replies.comments) |comment| try Comment.appendComment(allocator, inner, self.session, self.data.identity, kind, comment); 1128 try Comment.appendWindowNav(allocator, inner, self.session, self.data.identity, kind, &page.selected.comment.event.thread_id, &page.selected.id, page.replies); 1129 1130 var spacer = try ui.Spacer.init(allocator); 1131 errdefer spacer.deinit(allocator); 1132 try inner.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1133 1134 inner.getFocus().child_id = inner.children.keys()[0]; 1135 const sc = self.detailScroll(index); 1136 sc.x = 0; 1137 sc.y = 0; 1138 sc.getFocus().version +%= 1; 1139 return; 1140 } 1141 1142 if (description_page) { 1143 // the back link, in the title slot so the pane's input handling 1144 // applies to it unchanged. 1145 const back_label = try std.fmt.allocPrint(self.session.page_arena.allocator(), "← back to {s}", .{thread_name}); 1146 var tb = try wgt.TextBox(ui.Widget).init(allocator, back_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1147 errdefer tb.deinit(allocator); 1148 tb.getFocus().focusable = true; 1149 tb.getFocus().kind = .{ .custom = try listLink(self.session.page_arena, self.data.identity, entryStatus(entry), "", entry.id) }; 1150 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1151 } else { 1152 // the issue's title as a focusable word-wrapped text box. 1153 { 1154 var tb = try wgt.TextBox(ui.Widget).init(allocator, entry.record.event.title, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word, .label = " title " }); 1155 errdefer tb.deinit(allocator); 1156 tb.getFocus().focusable = true; 1157 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1158 } 1159 1160 self.author_id[index] = blk: { 1161 var tb = try ui.authorBox(allocator, self.session.page_arena, entry.author); 1162 errdefer tb.deinit(allocator); 1163 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1164 break :blk tb.getFocus().id; 1165 }; 1166 1167 // the issue's tags, each linking to this status's list filtered to 1168 // that tag. 1169 { 1170 var items: std.ArrayList(ui.TagFlow.Item) = .empty; 1171 defer items.deinit(allocator); 1172 var tag_iter = Event.tagIterator(entry.record.event.tags); 1173 while (tag_iter.next()) |tag| { 1174 if (tag.len == 0) continue; 1175 try items.append(allocator, .{ .text = tag, .link = try tagLink(self.session.page_arena, self.data.identity, entryStatus(entry), tag) }); 1176 } 1177 if (items.items.len > 0) { 1178 var tf = try ui.TagFlow.init(allocator); 1179 errdefer tf.deinit(allocator); 1180 try tf.setItems(allocator, items.items); 1181 try inner.children.put(allocator, tf.getFocus().id, .{ .widget = .{ .tag_flow = tf }, .rect = null, .min_size = null }); 1182 } 1183 } 1184 } 1185 1186 // the description as a focusable word-wrapped text box. past the limit 1187 // it's cut at the last whole line and links to the /description page, 1188 // which shows the whole thing. 1189 self.description_id[index] = blk: { 1190 const whole = entry.record.event.description; 1191 const cut_short = !description_page and whole.len > Data.max_description_size; 1192 const shown = if (cut_short) 1193 std.mem.trimEnd(u8, whole[0 .. std.mem.lastIndexOfScalar(u8, whole[0..Data.max_description_size], '\n') orelse 0], " \t\r\n") 1194 else if (whole.len == 0) 1195 "(no description)" 1196 else 1197 whole; 1198 var tb = try wgt.TextBox(ui.Widget).init(allocator, shown, .{ 1199 .border_style = .single, 1200 .rounded_corners = true, 1201 .wrap_kind = .word, 1202 .label = " description ", 1203 .bottom_label = if (cut_short) " click or press enter to see more " else "", 1204 }); 1205 errdefer tb.deinit(allocator); 1206 tb.getFocus().focusable = true; 1207 if (cut_short) tb.getFocus().kind = .{ .custom = try descriptionLink(self.session.page_arena, self.data.identity, entry.id) }; 1208 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1209 break :blk tb.getFocus().id; 1210 }; 1211 1212 const parent_route = commentsRoute(self.data.identity, entry.id, 0) orelse return error.RouteTooLong; 1213 try Attachment.appendRows(allocator, inner, self.session, self.data.identity, try parent_route.toUrl(self.session.page_arena), entry.attachments); 1214 1215 if (!description_page) { 1216 var reply = try Comment.linkBox(allocator, self.session, "new comment", newCommentRoute(self.data.identity, entry.id, "") orelse return error.RouteTooLong); 1217 errdefer reply.deinit(allocator); 1218 try inner.children.put(allocator, reply.getFocus().id, .{ .widget = .{ .text_box = reply }, .rect = null, .min_size = null }); 1219 1220 try Comment.appendCount(allocator, inner, entry.comments.count, "comment", "comments", self.session.page_arena.allocator()); 1221 for (entry.comments.comments) |comment| try Comment.appendComment(allocator, inner, self.session, self.data.identity, kind, comment); 1222 try Comment.appendWindowNav(allocator, inner, self.session, self.data.identity, kind, entry.id, null, entry.comments); 1223 1224 var spacer = try ui.Spacer.init(allocator); 1225 errdefer spacer.deinit(allocator); 1226 try inner.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1227 } 1228 1229 // select the title by default 1230 inner.getFocus().child_id = inner.children.keys()[title_child_index]; 1231 1232 // reset the scroll to the top for the newly-shown issue: directly on the 1233 // terminal (the wasm offset), and via a version bump on the web (so the 1234 // renderer's scroll id changes and JS drops the preserved position). 1235 const sc = self.detailScroll(index); 1236 sc.x = 0; 1237 sc.y = 0; 1238 sc.getFocus().version +%= 1; 1239 } 1240 1241 pub fn input(self: *This, allocator: std.mem.Allocator, raw_key: Key, root_focus: *Focus) !void { 1242 // wheel input moves focus like the arrows 1243 const key: Key = if (raw_key == .mouse and raw_key.mouse.action == .scroll) 1244 (if (raw_key.mouse.action.scroll == .up) .arrow_up else .arrow_down) 1245 else 1246 raw_key; 1247 1248 if (self.headerActive()) { 1249 // down from the tabs re-enters the stack if the selected view has 1250 // something to focus; other keys move the tabs. 1251 if (inp.vertDirection(key) == .down) { 1252 const enterable = if (self.viewStack().getSelected()) |selected| switch (selected.*) { 1253 .tag_flow => |*tf| tf.text_boxes.items.len > 0, 1254 // nothing focusable in the unauthorized view 1255 .unauthorized => false, 1256 else => true, 1257 } else false; 1258 if (enterable) root_focus.setFocus(self.box.children.keys()[stack_index]); 1259 } else { 1260 try self.header().input(allocator, key, root_focus); 1261 } 1262 return; 1263 } 1264 if (self.tagsViewActive()) { 1265 self.tagsViewInput(key, root_focus); 1266 return; 1267 } 1268 if (self.formViewActive()) { 1269 if (self.data.view == .remove) { 1270 try self.removeFormInput(allocator, key, root_focus); 1271 } else if (has_conflicts and self.data.view == .resolve) { 1272 try self.resolveInput(allocator, key, root_focus); 1273 } else if (self.data.view == .new_comment or self.data.view == .edit_comment) { 1274 try self.commentFormInput(allocator, key, root_focus); 1275 } else { 1276 try self.formInput(allocator, key, root_focus); 1277 } 1278 return; 1279 } 1280 const i = self.selectedSplitIndex() orelse return; 1281 if (self.detailActive(i)) { 1282 try self.detailInput(allocator, i, key, root_focus); 1283 } else { 1284 try self.listInput(i, key, root_focus); 1285 } 1286 } 1287 1288 // arrow keys move the tag selection; up from the top row crosses to the 1289 // header tabs. 1290 fn tagsViewInput(self: *This, key: Key, root_focus: *Focus) void { 1291 const tf = self.tagsView(); 1292 const cid = tf.focus.child_id orelse return; 1293 const cur = tf.indexOfFocusId(cid) orelse return; 1294 const count = tf.text_boxes.items.len; 1295 switch (key) { 1296 .arrow_left => if (cur > 0) root_focus.setFocus(tf.text_boxes.items[cur - 1].getFocus().id), 1297 .arrow_right => if (cur + 1 < count) root_focus.setFocus(tf.text_boxes.items[cur + 1].getFocus().id), 1298 .arrow_up => if (tf.rowStep(cur, false)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id) else self.focusHeader(root_focus), 1299 .arrow_down => if (tf.rowStep(cur, true)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id), 1300 .home => root_focus.setFocus(tf.text_boxes.items[0].getFocus().id), 1301 .end => root_focus.setFocus(tf.text_boxes.items[count - 1].getFocus().id), 1302 else => {}, 1303 } 1304 } 1305 1306 fn listInput(self: *This, index: usize, key: Key, root_focus: *Focus) !void { 1307 // up/down (and the scroll wheel) move the selection a row; page up/down 1308 // jump a fixed amount. right/Enter cross into the detail pane. up from 1309 // the top row crosses into the header tabs. 1310 if (inp.rowDelta(key, @intCast(self.listBox(index).children.count()))) |delta| { 1311 const lb = self.listBox(index); 1312 const at_top = if (lb.getFocus().child_id) |cid| lb.children.getIndex(cid) == 0 else true; 1313 if (delta < 0 and at_top) return self.focusHeader(root_focus); 1314 ui.moveRowFocus(lb, self.listScroll(index), root_focus, delta); 1315 return; 1316 } 1317 switch (key) { 1318 .enter, .arrow_right => try self.focusDetail(index, root_focus), 1319 else => {}, 1320 } 1321 } 1322 1323 fn detailInput(self: *This, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !void { 1324 switch (key) { 1325 .page_up => { 1326 self.pageDetail(index, root_focus, -10); 1327 return; 1328 }, 1329 .page_down => { 1330 self.pageDetail(index, root_focus, 10); 1331 return; 1332 }, 1333 .home => { 1334 self.jumpDetail(index, root_focus, false); 1335 return; 1336 }, 1337 .end => { 1338 self.jumpDetail(index, root_focus, true); 1339 return; 1340 }, 1341 else => {}, 1342 } 1343 if (self.data.comment_page != null and std.mem.eql(u8, self.window(index).items[self.detailed_index[index] orelse return].id, self.data.selected_id)) { 1344 try self.commentInput(allocator, index, key, root_focus); 1345 } else if (self.toolRowFocused(index)) { 1346 try self.toolRowInput(allocator, index, key, root_focus); 1347 } else if (self.titleFocused(index)) { 1348 try self.titleInput(index, key, root_focus); 1349 } else if (self.authorFocused(index)) { 1350 try self.authorInput(index, key, root_focus); 1351 } else if (self.tagsFocused(index)) { 1352 try self.tagsInput(index, key, root_focus); 1353 } else if (self.descriptionFocused(index)) { 1354 try self.descriptionInput(index, key, root_focus); 1355 } else if (try self.attachmentInput(allocator, index, key, root_focus)) {} else { 1356 try self.commentInput(allocator, index, key, root_focus); 1357 } 1358 } 1359 1360 fn attachmentInput(self: *This, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !bool { 1361 const child_index = self.focusedDetailChild(index, root_focus) orelse return false; 1362 const child = &self.detailInner(index).children.values()[child_index].widget; 1363 const row = switch (child.*) { 1364 .box => |*box| box, 1365 else => return false, 1366 }; 1367 const attachment_id = Attachment.removeId(row) orelse return false; 1368 if (row.children.count() < 2) return false; 1369 const remove_id = row.children.keys()[1]; 1370 switch (key) { 1371 .arrow_left => if (!self.moveCommentHorizontal(index, root_focus, false)) try self.focusList(index, root_focus), 1372 .arrow_right => _ = self.moveCommentHorizontal(index, root_focus, true), 1373 .arrow_up => _ = self.moveDetailVertical(index, root_focus, false), 1374 .arrow_down => _ = self.moveDetailVertical(index, root_focus, true), 1375 .enter => if (row.getFocus().child_id == remove_id) try self.removeEvent(allocator, .attach, attachment_id), 1376 .mouse => |mouse| if (inp.leftClickOn(root_focus, remove_id, mouse)) try self.removeEvent(allocator, .attach, attachment_id), 1377 else => {}, 1378 } 1379 return true; 1380 } 1381 1382 // the tool row: enter or a click on the open/close button flips the 1383 // issue's status; the edit and resolve buttons are a: links the host 1384 // follows. arrows cross between the buttons and to the neighboring 1385 // widgets. 1386 fn toolRowInput(self: *This, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !void { 1387 const row = self.toolRow(index); 1388 const cur = if (row.getFocus().child_id) |cid| row.children.getIndex(cid) orelse return else return; 1389 const on_status = if (self.status_button_id[index]) |id| row.getFocus().child_id == id else false; 1390 switch (key) { 1391 .arrow_left => if (cur > first_in_row_index) root_focus.setFocus(row.children.keys()[cur - 1]) else try self.focusList(index, root_focus), 1392 .arrow_right => if (cur + 1 < row.children.count()) root_focus.setFocus(row.children.keys()[cur + 1]), 1393 .arrow_up => self.focusHeader(root_focus), 1394 .arrow_down => { 1395 self.focusDetailEdge(index, root_focus, false); 1396 self.detailScroll(index).y = 0; 1397 }, 1398 .enter => if (on_status) try self.toggleStatus(allocator, index), 1399 .mouse => |mouse| if (self.status_button_id[index]) |id| { 1400 if (inp.leftClickOn(root_focus, id, mouse)) try self.toggleStatus(allocator, index); 1401 }, 1402 else => {}, 1403 } 1404 } 1405 1406 fn titleInput(self: *This, index: usize, key: Key, root_focus: *Focus) !void { 1407 switch (key) { 1408 .arrow_left => try self.focusList(index, root_focus), 1409 .arrow_up => self.focusToolRow(index, root_focus), 1410 .arrow_down => _ = self.moveDetailVertical(index, root_focus, true), 1411 else => {}, 1412 } 1413 } 1414 1415 // the author box's a: link (when it has one) is followed by the host on 1416 // enter / a click; arrows cross to the neighboring widgets. 1417 fn authorInput(self: *This, index: usize, key: Key, root_focus: *Focus) !void { 1418 switch (key) { 1419 .arrow_left => try self.focusList(index, root_focus), 1420 .arrow_up => _ = self.moveDetailVertical(index, root_focus, false), 1421 .arrow_down => _ = self.moveDetailVertical(index, root_focus, true), 1422 else => {}, 1423 } 1424 } 1425 1426 fn descriptionInput(self: *This, index: usize, key: Key, root_focus: *Focus) !void { 1427 const sc = self.detailScroll(index); 1428 switch (key) { 1429 .arrow_left => return self.focusList(index, root_focus), 1430 // the terminal moves through the description one line at a time; 1431 // the web lets focus changes drive its native scroll. 1432 .arrow_up => { 1433 if (!self.session.is_terminal) { 1434 _ = self.moveDetailVertical(index, root_focus, false); 1435 return; 1436 } 1437 if (self.focusAdjacentVisible(index, root_focus, false)) return; 1438 const before = sc.y; 1439 sc.y -= 1; 1440 sc.clampToContent(); 1441 if (sc.y == before) _ = self.moveDetailVertical(index, root_focus, false); 1442 return; 1443 }, 1444 .arrow_down => { 1445 if (!self.session.is_terminal) { 1446 _ = self.moveDetailVertical(index, root_focus, true); 1447 return; 1448 } 1449 if (self.focusAdjacentVisible(index, root_focus, true)) return; 1450 const before = sc.y; 1451 sc.y += 1; 1452 sc.clampToContent(); 1453 if (sc.y == before) _ = self.moveDetailVertical(index, root_focus, true); 1454 return; 1455 }, 1456 else => return, 1457 } 1458 sc.clampToContent(); 1459 } 1460 1461 fn commentInput(self: *This, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !void { 1462 _ = allocator; 1463 switch (key) { 1464 .arrow_left => if (!self.moveCommentHorizontal(index, root_focus, false)) return self.focusList(index, root_focus), 1465 .arrow_right => _ = self.moveCommentHorizontal(index, root_focus, true), 1466 .arrow_up => _ = self.moveDetailVertical(index, root_focus, false), 1467 .arrow_down => _ = self.moveDetailVertical(index, root_focus, true), 1468 else => return, 1469 } 1470 } 1471 1472 // page the detail scroll, then focus the first or last visible widget. 1473 fn pageDetail(self: *This, index: usize, root_focus: *Focus, delta: isize) void { 1474 if (!self.session.is_terminal) return; 1475 const sc = self.detailScroll(index); 1476 sc.y += delta; 1477 sc.clampToContent(); 1478 self.focusVisible(index, root_focus, delta > 0); 1479 } 1480 1481 // jump to the detail's first or last focusable widget. the terminal pins 1482 // its synthetic scroll too; the browser scrolls to the new focus itself. 1483 fn jumpDetail(self: *This, index: usize, root_focus: *Focus, to_end: bool) void { 1484 if (self.session.is_terminal) { 1485 const sc = self.detailScroll(index); 1486 sc.y = if (to_end) std.math.maxInt(isize) else 0; 1487 sc.clampToContent(); 1488 self.focusVisible(index, root_focus, to_end); 1489 } else { 1490 self.focusDetailEdge(index, root_focus, to_end); 1491 } 1492 } 1493 1494 fn focusDetailEdge(self: *This, index: usize, root_focus: *Focus, last: bool) void { 1495 const focus = self.detailInner(index).getFocus(); 1496 var chosen: ?usize = null; 1497 for (focus.children.keys(), focus.children.values()) |id, child| { 1498 if (!child.focus.focusable) continue; 1499 chosen = id; 1500 if (!last) break; 1501 } 1502 if (chosen) |id| root_focus.setFocus(id); 1503 } 1504 1505 fn detailRectVisible(self: *This, index: usize, rect: layout.IRect) bool { 1506 const sc = self.detailScroll(index); 1507 const viewport = sc.grid orelse return false; 1508 const top = sc.y; 1509 const bottom = top + @as(isize, @intCast(viewport.size.height - sc.bar_h)); 1510 return rect.y + @as(isize, @intCast(rect.size.height)) > top and rect.y < bottom; 1511 } 1512 1513 // focus the top- or bottom-most focusable widget intersecting the viewport. 1514 fn focusVisible(self: *This, index: usize, root_focus: *Focus, last: bool) void { 1515 const inner = self.detailInner(index); 1516 var offset: usize = 0; 1517 while (offset < inner.children.count()) : (offset += 1) { 1518 const child_index = if (last) inner.children.count() - 1 - offset else offset; 1519 if (self.focusVisibleChild(index, child_index, root_focus, last)) return; 1520 } 1521 } 1522 1523 fn focusVisibleChild(self: *This, index: usize, child_index: usize, root_focus: *Focus, last: bool) bool { 1524 const child = &self.detailInner(index).children.values()[child_index]; 1525 const child_rect = child.rect orelse return false; 1526 var chosen: ?usize = null; 1527 if (child.widget.getFocus().focusable and self.detailRectVisible(index, child_rect)) { 1528 const id = self.detailInner(index).children.keys()[child_index]; 1529 chosen = id; 1530 if (!last) { 1531 root_focus.setFocus(id); 1532 return true; 1533 } 1534 } 1535 1536 for (child.widget.getFocus().children.keys(), child.widget.getFocus().children.values()) |id, focus_child| { 1537 if (!focus_child.focus.focusable) continue; 1538 const rect: layout.IRect = .{ 1539 .x = child_rect.x + @as(isize, @intCast(focus_child.rect.x)), 1540 .y = child_rect.y + @as(isize, @intCast(focus_child.rect.y)), 1541 .size = focus_child.rect.size, 1542 }; 1543 if (!self.detailRectVisible(index, rect)) continue; 1544 chosen = id; 1545 if (!last) break; 1546 } 1547 if (chosen) |id| { 1548 root_focus.setFocus(id); 1549 return true; 1550 } 1551 return false; 1552 } 1553 1554 fn focusAdjacentVisible(self: *This, index: usize, root_focus: *Focus, down: bool) bool { 1555 const inner = self.detailInner(index); 1556 var next = self.focusedDetailChild(index, root_focus) orelse return false; 1557 while (true) { 1558 if (down) { 1559 next += 1; 1560 if (next >= inner.children.count()) return false; 1561 } else { 1562 if (next == 0) return false; 1563 next -= 1; 1564 } 1565 if (self.focusVisibleChild(index, next, root_focus, !down)) { 1566 self.focusDetailChild(index, next, !down, root_focus); 1567 return true; 1568 } 1569 } 1570 } 1571 1572 fn focusedDetailChild(self: *This, index: usize, root_focus: *Focus) ?usize { 1573 const inner = self.detailInner(index); 1574 var id = root_focus.grandchild_id orelse return null; 1575 while (inner.getFocus().children.get(id)) |child| { 1576 if (child.parent_id == inner.getFocus().id) return inner.children.getIndex(id); 1577 id = child.parent_id; 1578 } 1579 return null; 1580 } 1581 1582 fn detailChildFocusable(self: *This, index: usize, child_index: usize) bool { 1583 const child = &self.detailInner(index).children.values()[child_index].widget; 1584 const focus = child.getFocus(); 1585 if (focus.focusable) return true; 1586 for (focus.children.values()) |item| { 1587 if (item.focus.focusable) return true; 1588 } 1589 return false; 1590 } 1591 1592 fn focusDetailChild(self: *This, index: usize, child_index: usize, last: bool, root_focus: *Focus) void { 1593 const inner = self.detailInner(index); 1594 const child = &inner.children.values()[child_index]; 1595 var target = inner.children.keys()[child_index]; 1596 var rect = child.rect orelse return; 1597 switch (child.widget) { 1598 .repo_comment => |*comment| { 1599 if (comment.rowRect(last)) |row_rect| { 1600 rect.x += row_rect.x; 1601 rect.y += row_rect.y; 1602 rect.size = row_rect.size; 1603 } 1604 if (last) comment.focusBody(root_focus) else comment.focusMetadata(root_focus); 1605 }, 1606 .box => |*box| if (box.children.count() > 0) { 1607 target = box.children.keys()[if (last) box.children.count() - 1 else 0]; 1608 root_focus.setFocus(target); 1609 }, 1610 else => root_focus.setFocus(target), 1611 } 1612 const sc = self.detailScroll(index); 1613 if (sc.grid) |viewport| { 1614 const viewport_height = viewport.size.height - sc.bar_h; 1615 if (rect.size.height > viewport_height) { 1616 const bottom_aligned = rect.y + @as(isize, @intCast(rect.size.height - viewport_height)); 1617 sc.y = std.math.clamp(sc.y, rect.y, bottom_aligned); 1618 sc.clampToContent(); 1619 return; 1620 } 1621 } 1622 sc.scrollToRect(rect); 1623 } 1624 1625 fn moveDetailVertical(self: *This, index: usize, root_focus: *Focus, down: bool) bool { 1626 const inner = self.detailInner(index); 1627 const current = self.focusedDetailChild(index, root_focus) orelse return false; 1628 if (inner.children.values()[current].widget == .repo_comment) { 1629 const comment = &inner.children.values()[current].widget.repo_comment; 1630 if (down and !comment.bodyFocused()) { 1631 self.focusDetailChild(index, current, true, root_focus); 1632 return true; 1633 } 1634 if (!down and comment.bodyFocused()) { 1635 self.focusDetailChild(index, current, false, root_focus); 1636 return true; 1637 } 1638 } 1639 1640 var next = current; 1641 while (true) { 1642 if (down) { 1643 next += 1; 1644 if (next >= inner.children.count()) return false; 1645 } else { 1646 if (next == 0) return false; 1647 next -= 1; 1648 } 1649 if (!self.detailChildFocusable(index, next)) continue; 1650 self.focusDetailChild(index, next, !down, root_focus); 1651 return true; 1652 } 1653 } 1654 1655 fn moveCommentHorizontal(self: *This, index: usize, root_focus: *Focus, right: bool) bool { 1656 const inner = self.detailInner(index); 1657 const current = self.focusedDetailChild(index, root_focus) orelse return false; 1658 const child = &inner.children.values()[current]; 1659 if (child.widget == .repo_comment) { 1660 const moved = child.widget.repo_comment.moveHorizontal(root_focus, right); 1661 if (moved) if (child.rect) |rect| self.detailScroll(index).scrollToRect(rect); 1662 return moved; 1663 } 1664 const row = switch (child.widget) { 1665 .box => |*box| box, 1666 else => return false, 1667 }; 1668 const selected = row.getFocus().child_id orelse return false; 1669 const selected_index = row.children.getIndex(selected) orelse return false; 1670 const target = if (right) selected_index + 1 else selected_index -| 1; 1671 if (target == selected_index or target >= row.children.count()) return false; 1672 root_focus.setFocus(row.children.keys()[target]); 1673 if (child.rect) |rect| self.detailScroll(index).scrollToRect(rect); 1674 return true; 1675 } 1676 1677 // up/down (and tab/shift+tab) move between a form's fields; up from the 1678 // title crosses into the header tabs. the multiline description keeps 1679 // enter and any up/down that has a row to move to. 1680 fn formInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1681 const form = self.threadForm() orelse return; 1682 const cid = form.getFocus().child_id orelse return; 1683 const cur = form.children.getIndex(cid) orelse return; 1684 1685 if (cur == description_field_index) { 1686 const child = &form.children.values()[cur]; 1687 if (try multilineKeepsKey(&child.widget.text_input, allocator, key)) 1688 return child.widget.input(allocator, key, root_focus); 1689 } 1690 1691 switch (key) { 1692 .arrow_up, .back_tab => if (cur > 0) 1693 root_focus.setFocus(form.children.keys()[cur - 1]) 1694 else 1695 self.focusHeader(root_focus), 1696 .arrow_down, .tab => if (cur < submit_field_index) { 1697 root_focus.setFocus(form.children.keys()[cur + 1]); 1698 }, 1699 .enter => if (cur == submit_field_index) try self.submitForm(allocator), 1700 .mouse => |mouse| if (cur == submit_field_index) { 1701 const submit = &form.children.values()[cur].widget.submit_button; 1702 if (inp.leftClickOn(root_focus, submit.buttonId(), mouse)) try self.submitForm(allocator); 1703 }, 1704 else => try form.children.values()[cur].widget.input(allocator, key, root_focus), 1705 } 1706 } 1707 1708 fn commentFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1709 const form = self.threadForm() orelse return; 1710 const cid = form.getFocus().child_id orelse return; 1711 const cur = form.children.getIndex(cid) orelse return; 1712 const child = &form.children.values()[cur]; 1713 1714 if (cur == comment_body_field_index and try multilineKeepsKey(&child.widget.text_input, allocator, key)) 1715 return child.widget.input(allocator, key, root_focus); 1716 1717 switch (key) { 1718 .arrow_up, .back_tab => if (cur > comment_author_field_index) 1719 root_focus.setFocus(form.children.keys()[cur - 1]) 1720 else 1721 self.focusHeader(root_focus), 1722 .arrow_down, .tab => if (cur < comment_submit_field_index) 1723 root_focus.setFocus(form.children.keys()[cur + 1]), 1724 .enter => if (cur == comment_submit_field_index) try self.submitComment(allocator), 1725 .mouse => |mouse| if (cur == comment_submit_field_index) { 1726 const submit = &child.widget.submit_button; 1727 if (inp.leftClickOn(root_focus, submit.buttonId(), mouse)) try self.submitComment(allocator); 1728 }, 1729 else => try child.widget.input(allocator, key, root_focus), 1730 } 1731 } 1732 1733 fn removeFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1734 const form = self.removeForm() orelse return; 1735 const button_id = form.children.keys()[1]; 1736 switch (key) { 1737 .arrow_up, .back_tab => self.focusHeader(root_focus), 1738 .enter => try self.submitRemove(allocator), 1739 .mouse => |mouse| if (inp.leftClickOn(root_focus, button_id, mouse)) try self.submitRemove(allocator), 1740 else => {}, 1741 } 1742 } 1743 1744 // the multiline hunk inputs keep enter and any up/down that has a row to 1745 // move to; enter on a "use this" link is a navigation the host follows 1746 // before this runs. 1747 fn resolveInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1748 const form = self.threadForm() orelse return; 1749 const cid = form.getFocus().child_id orelse return; 1750 const cur = form.children.getIndex(cid) orelse return; 1751 const child = &form.children.values()[cur]; 1752 1753 if (child.widget == .text_input) { 1754 const ti = &child.widget.text_input; 1755 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 1756 return child.widget.input(allocator, key, root_focus); 1757 } 1758 1759 const on_submit = child.widget == .submit_button; 1760 1761 switch (key) { 1762 .arrow_up, .back_tab => if (resolveStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 1763 .arrow_down, .tab => if (resolveStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 1764 .arrow_left, .arrow_right => switch (child.widget) { 1765 .box => |*row| { 1766 const row_cid = row.getFocus().child_id orelse return; 1767 const row_index = row.children.getIndex(row_cid) orelse return; 1768 if (key == .arrow_left) { 1769 if (row_index > 0) root_focus.setFocus(row.children.keys()[row_index - 1]); 1770 } else if (row_index + 1 < row.children.count()) { 1771 root_focus.setFocus(row.children.keys()[row_index + 1]); 1772 } 1773 }, 1774 else => try child.widget.input(allocator, key, root_focus), 1775 }, 1776 .enter => if (on_submit) try self.submitResolution(allocator), 1777 .mouse => |mouse| if (on_submit) { 1778 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 1779 }, 1780 else => try child.widget.input(allocator, key, root_focus), 1781 } 1782 } 1783 1784 // a multiline input keeps enter and any up/down that has a row to move to 1785 fn multilineKeepsKey(text_input: *wgt.TextInput(ui.Widget), allocator: std.mem.Allocator, key: Key) !bool { 1786 return switch (key) { 1787 .enter => true, 1788 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 1789 .arrow_down => !try text_input.cursorOnLastRow(allocator), 1790 else => false, 1791 }; 1792 } 1793 1794 // the neighboring focusable resolve-form child, skipping the spacer and 1795 // the blank gap rows 1796 fn resolveStep(form: *wgt.Box(ui.Widget), cur: usize, down: bool) ?usize { 1797 var i = cur; 1798 while (true) { 1799 if (down) { 1800 i += 1; 1801 if (i >= form.children.count()) return null; 1802 } else { 1803 if (i == 0) return null; 1804 i -= 1; 1805 } 1806 switch (form.children.values()[i].widget) { 1807 .spacer, .text => continue, 1808 else => return i, 1809 } 1810 } 1811 } 1812 1813 // focus the resolve-form child at `i` (a version row focuses its selected 1814 // child) and keep it visible on the terminal 1815 fn focusResolveChild(self: *This, form: *wgt.Box(ui.Widget), i: usize, root_focus: *Focus) void { 1816 const child = &form.children.values()[i]; 1817 switch (child.widget) { 1818 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 1819 else => root_focus.setFocus(form.children.keys()[i]), 1820 } 1821 if (self.session.is_terminal) { 1822 if (self.resolveScroll()) |sc| { 1823 if (child.rect) |rect| sc.scrollToRect(rect); 1824 } 1825 } 1826 } 1827 1828 // re-emit the conflicted issue's event with the resolved content; any 1829 // event on the issue settles its conflict entry. this is the terminal 1830 // path; the web posts the form to the resolve route. 1831 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 1832 if (comptime wasm) return; 1833 const io = self.session.io orelse return; 1834 const src = self.data.repo_source orelse return; 1835 const entry = self.data.selectedThread() orelse return; 1836 const author = (try self.session.eventAuthor()) orelse return; 1837 const form = self.threadForm() orelse return; 1838 1839 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 1840 var title: ?[]u8 = null; 1841 var tags: ?[]u8 = null; 1842 var hunks: std.ArrayList([]const u8) = .empty; 1843 defer { 1844 if (title) |t| allocator.free(t); 1845 if (tags) |t| allocator.free(t); 1846 for (hunks.items) |h| allocator.free(h); 1847 hunks.deinit(allocator); 1848 } 1849 for (form.children.values()) |*child| switch (child.widget) { 1850 .text_input => |*ti| { 1851 const text = try ti.text(allocator); 1852 errdefer allocator.free(text); 1853 if (std.mem.eql(u8, ti.options.name, "title")) { 1854 title = text; 1855 } else if (std.mem.eql(u8, ti.options.name, "tags")) { 1856 tags = text; 1857 } else { 1858 try hunks.append(allocator, text); 1859 } 1860 }, 1861 else => {}, 1862 }; 1863 1864 var id_bytes: [evt.event_id_size]u8 = undefined; 1865 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 1866 1867 switch (src.repo_kind) { 1868 inline else => |repo_kind| { 1869 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 1870 defer any_repo.deinit(io, allocator); 1871 switch (any_repo) { 1872 inline else => |*repo| Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .resolve = .{ 1873 .title = title, 1874 .tags = tags, 1875 .hunks = hunks.items, 1876 } }, author) catch |err| switch (err) { 1877 // leave the form up for correction 1878 error.InvalidFields => return, 1879 else => |e| return e, 1880 }, 1881 } 1882 }, 1883 } 1884 1885 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 1886 try self.session.navigate(route); 1887 } 1888 1889 // commit a new or edited comment and navigate to its permalink. this is the 1890 // terminal path; the web posts the form to its comment route. 1891 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 1892 if (comptime wasm) return; 1893 const io = self.session.io orelse return; 1894 const src = self.data.repo_source orelse return; 1895 const author = (try self.session.eventAuthor()) orelse return; 1896 const form = self.threadForm() orelse return; 1897 const body_input = &form.children.values()[comment_body_field_index].widget.text_input; 1898 const body = try body_input.text(allocator); 1899 defer allocator.free(body); 1900 if (!evt.Comment.fieldsValid(body)) return; 1901 1902 var thread_id: [evt.event_id_size * 2]u8 = undefined; 1903 @memcpy(&thread_id, self.data.selected_id); 1904 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 1905 var parent: [evt.event_id_size * 2]u8 = undefined; 1906 @memcpy(&parent, self.data.comment_id); 1907 break :blk parent; 1908 }; 1909 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 1910 const editing = self.data.view == .edit_comment; 1911 switch (src.repo_kind) { 1912 inline else => |repo_kind| { 1913 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 1914 defer any_repo.deinit(io, allocator); 1915 switch (any_repo) { 1916 inline else => |*repo| if (editing) { 1917 var comment_id: [evt.event_id_size]u8 = undefined; 1918 _ = std.fmt.hexToBytes(&comment_id, self.data.comment_id) catch return; 1919 try evt.Comment.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &comment_id, body, author); 1920 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 1921 } else { 1922 event_id_hex = try evt.Comment.create(repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &parent_id, body, author); 1923 }, 1924 } 1925 }, 1926 } 1927 1928 body_input.clear(allocator); 1929 const route = commentRoute(self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 1930 try self.session.navigate(route); 1931 } 1932 1933 // the terminal submit paths: the new form commits a new-issue event, the 1934 // edit form re-emits the selected issue's event with the form's content. 1935 // the web posts the forms to their routes instead. 1936 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 1937 if (self.data.view == .edit) { 1938 try self.submitEditedThread(allocator); 1939 } else { 1940 try self.submitNewThread(allocator); 1941 } 1942 } 1943 1944 // commit the new issue to the repo's events branch and navigate to it. 1945 // this is the terminal path; the web posts the form to the issue route, 1946 // so the wasm side never runs (or compiles) the repo access below. 1947 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 1948 if (comptime wasm) return; 1949 const io = self.session.io orelse return; 1950 const src = self.data.repo_source orelse return; 1951 const author = (try self.session.eventAuthor()) orelse return; 1952 1953 const form = self.threadForm() orelse return; 1954 const title_input = &form.children.values()[title_field_index].widget.text_input; 1955 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 1956 const description_input = &form.children.values()[description_field_index].widget.text_input; 1957 1958 const title = try title_input.text(allocator); 1959 defer allocator.free(title); 1960 const tags = try tags_input.text(allocator); 1961 defer allocator.free(tags); 1962 const description = try description_input.text(allocator); 1963 defer allocator.free(description); 1964 1965 if (!Event.fieldsValid(title, tags)) return; 1966 1967 var id_bytes: [evt.event_id_size]u8 = undefined; 1968 io.random(&id_bytes); 1969 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 1970 1971 const event = evt.EventWithId{ 1972 .id = event_id_hex, 1973 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 1974 .author = author, 1975 .event = @unionInit(evt.Event, @tagName(kind), Event{ 1976 .title = title, 1977 .description = description, 1978 .tags = tags, 1979 }), 1980 }; 1981 1982 switch (src.repo_kind) { 1983 inline else => |repo_kind| { 1984 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 1985 defer any_repo.deinit(io, allocator); 1986 switch (any_repo) { 1987 inline else => |*repo| try evt.consume(repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 1988 } 1989 }, 1990 } 1991 1992 // wipe the form so a return visit starts fresh 1993 title_input.clear(allocator); 1994 tags_input.clear(allocator); 1995 description_input.clear(allocator); 1996 1997 const route = listRoute(self.data.identity, @enumFromInt(0), "", &event_id_hex) orelse return; 1998 try self.session.navigate(route); 1999 } 2000 2001 // re-emit the selected issue's event with the form's content (status 2002 // preserved), then reload the issue's page. this is the terminal path; 2003 // the web posts the form to the edit route. 2004 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 2005 if (comptime wasm) return; 2006 const io = self.session.io orelse return; 2007 const src = self.data.repo_source orelse return; 2008 const entry = self.data.selectedThread() orelse return; 2009 const author = (try self.session.eventAuthor()) orelse return; 2010 2011 const form = self.threadForm() orelse return; 2012 const title_input = &form.children.values()[title_field_index].widget.text_input; 2013 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 2014 const description_input = &form.children.values()[description_field_index].widget.text_input; 2015 2016 const title = try title_input.text(allocator); 2017 defer allocator.free(title); 2018 const tags = try tags_input.text(allocator); 2019 defer allocator.free(tags); 2020 const description = try description_input.text(allocator); 2021 defer allocator.free(description); 2022 2023 if (!Event.fieldsValid(title, tags)) return; 2024 2025 var id_bytes: [evt.event_id_size]u8 = undefined; 2026 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2027 2028 switch (src.repo_kind) { 2029 inline else => |repo_kind| { 2030 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2031 defer any_repo.deinit(io, allocator); 2032 switch (any_repo) { 2033 inline else => |*repo| if (has_status) 2034 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2035 .title = title, 2036 .tags = tags, 2037 .description = description, 2038 } }, author) 2039 else 2040 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, tags, description, author), 2041 } 2042 }, 2043 } 2044 2045 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2046 try self.session.navigate(route); 2047 } 2048 2049 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2050 const comment = self.data.comment_id.len != 0; 2051 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2052 var id: [evt.event_id_size]u8 = undefined; 2053 _ = std.fmt.hexToBytes(&id, event_id) catch return; 2054 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2055 } 2056 2057 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2058 if (comptime wasm) return; 2059 const io = self.session.io orelse return; 2060 const src = self.data.repo_source orelse return; 2061 const author = (try self.session.eventAuthor()) orelse return; 2062 2063 switch (src.repo_kind) { 2064 inline else => |repo_kind| { 2065 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2066 defer any_repo.deinit(io, allocator); 2067 switch (any_repo) { 2068 inline else => |*repo| try evt.remove(repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2069 } 2070 }, 2071 } 2072 2073 const id_hex = std.fmt.bytesToHex(id, .lower); 2074 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2075 try self.session.navigate(route); 2076 } 2077 2078 // flip the shown issue's status by re-emitting its event, then reload the 2079 // page rooted at the issue so the view reflects the change. this is the 2080 // terminal path; the web posts the button's form to the status route. 2081 fn toggleStatus(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2082 if (comptime !has_status) return; 2083 if (comptime wasm) return; 2084 const io = self.session.io orelse return; 2085 const src = self.data.repo_source orelse return; 2086 const sel = self.detailed_index[index] orelse return; 2087 const entry = self.window(index).items[sel]; 2088 const author = (try self.session.eventAuthor()) orelse return; 2089 2090 const status: Status = switch (entryStatus(entry)) { 2091 .open => .closed, 2092 .closed => .open, 2093 }; 2094 2095 var id_bytes: [evt.event_id_size]u8 = undefined; 2096 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2097 2098 switch (src.repo_kind) { 2099 inline else => |repo_kind| { 2100 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2101 defer any_repo.deinit(io, allocator); 2102 switch (any_repo) { 2103 inline else => |*repo| try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2104 } 2105 }, 2106 } 2107 2108 const route = listRoute(self.data.identity, status, "", entry.id) orelse return; 2109 try self.session.navigate(route); 2110 } 2111 2112 // arrow keys move the tag selection; at the flow's edges focus crosses to 2113 // the neighboring widgets. 2114 fn tagsInput(self: *This, index: usize, key: Key, root_focus: *Focus) !void { 2115 const tf = self.tagFlow(index) orelse return; 2116 const cid = tf.focus.child_id orelse return; 2117 const cur = tf.indexOfFocusId(cid) orelse return; 2118 const count = tf.text_boxes.items.len; 2119 switch (key) { 2120 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 2121 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 2122 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2123 self.focusTag(index, tf, root_focus, i); 2124 } else { 2125 _ = self.moveDetailVertical(index, root_focus, false); 2126 }, 2127 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2128 self.focusTag(index, tf, root_focus, i); 2129 } else { 2130 _ = self.moveDetailVertical(index, root_focus, true); 2131 }, 2132 .home => self.focusTag(index, tf, root_focus, 0), 2133 .end => self.focusTag(index, tf, root_focus, count - 1), 2134 else => {}, 2135 } 2136 } 2137 2138 const title_child_index: usize = 0; 2139 const tags_child_index: usize = 2; 2140 2141 // the tool row's first child after the spacer that pushes it right 2142 const first_in_row_index: usize = 1; 2143 2144 fn tagFlow(self: *This, index: usize) ?*ui.TagFlow { 2145 const inner = self.detailInner(index); 2146 if (inner.children.count() <= tags_child_index) return null; 2147 return switch (inner.children.values()[tags_child_index].widget) { 2148 .tag_flow => |*tf| tf, 2149 else => null, 2150 }; 2151 } 2152 2153 fn tagsFocused(self: *This, index: usize) bool { 2154 const inner = self.detailInner(index); 2155 const cid = inner.getFocus().child_id orelse return false; 2156 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 2157 } 2158 2159 fn toolRowFocused(self: *This, index: usize) bool { 2160 const outer = self.detailOuter(index); 2161 const cid = outer.getFocus().child_id orelse return false; 2162 return outer.children.getIndex(cid) == tool_row_index; 2163 } 2164 2165 fn focusTag(self: *This, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2166 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2167 // keep the tag visible on the terminal: its rect offset by the flow's 2168 // position in the pane. 2169 if (self.session.is_terminal and item < tf.rects.items.len) { 2170 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 2171 var rect = tf.rects.items[item]; 2172 rect.x += flow_rect.x; 2173 rect.y += flow_rect.y; 2174 self.detailScroll(index).scrollToRect(rect); 2175 } 2176 } 2177 } 2178 2179 fn titleFocused(self: *This, index: usize) bool { 2180 const inner = self.detailInner(index); 2181 const cid = inner.getFocus().child_id orelse return false; 2182 return inner.children.getIndex(cid) == title_child_index; 2183 } 2184 2185 fn authorFocused(self: *This, index: usize) bool { 2186 const inner = self.detailInner(index); 2187 const cid = inner.getFocus().child_id orelse return false; 2188 return cid == self.author_id[index]; 2189 } 2190 2191 fn descriptionFocused(self: *This, index: usize) bool { 2192 const cid = self.detailInner(index).getFocus().child_id orelse return false; 2193 return cid == self.description_id[index]; 2194 } 2195 2196 // return to the tool row's last-focused button (the header when the 2197 // description page shows no row). 2198 fn focusToolRow(self: *This, index: usize, root_focus: *Focus) void { 2199 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2200 root_focus.setFocus(cid); 2201 } 2202 2203 // enter the detail pane. an empty pane (no issues) can't be entered. 2204 fn focusDetail(self: *This, index: usize, root_focus: *Focus) !void { 2205 if (self.detailInner(index).children.count() == 0) return; 2206 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2207 } 2208 2209 // return to the list. 2210 fn focusList(self: *This, index: usize, root_focus: *Focus) !void { 2211 root_focus.setFocus(self.listScroll(index).getFocus().id); 2212 } 2213 2214 // cross to the header tabs above the stack. 2215 fn focusHeader(self: *This, root_focus: *Focus) void { 2216 root_focus.setFocus(self.box.children.keys()[header_index]); 2217 } 2218 2219 pub fn clearGrid(self: *This) void { 2220 self.box.clearGrid(); 2221 } 2222 2223 pub fn getGrid(self: This) ?Grid { 2224 return self.box.getGrid(); 2225 } 2226 2227 pub fn getFocus(self: *This) *Focus { 2228 return self.box.getFocus(); 2229 } 2230 2231 // for the parent's "scroll up at the top jumps to the header" check: at the 2232 // top only while the header tabs hold focus, so up from the split 2233 // crosses into the tabs first. 2234 pub fn getSelectedIndex(self: *This) ?usize { 2235 return if (self.headerActive()) 0 else 1; 2236 } 2237 }; 2238 } 2239