╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1844 } 1845 1846 fn focusDetailEdge(self: *View, index: usize, root_focus: *Focus, last: bool) void { 1847 const focus = self.detailInner(index).getFocus(); 1848 var chosen: ?usize = null; 1849 for (focus.children.keys(), focus.children.values()) |id, child| { 1850 if (!child.focus.focusable) continue; 1851 chosen = id; 1852 if (!last) break; 1853 } 1854 if (chosen) |id| root_focus.setFocus(id); 1855 } 1856 1857 fn detailRectVisible(self: *View, index: usize, rect: layout.IRect) bool { 1858 const sc = self.detailScroll(index); 1859 const viewport = sc.grid orelse return false; 1860 const top = sc.y; 1861 const bottom = top + @as(isize, @intCast(viewport.size.height - sc.bar_h)); 1862 return rect.y + @as(isize, @intCast(rect.size.height)) > top and rect.y < bottom; 1863 } 1864 1865 // focus the top- or bottom-most focusable widget intersecting the viewport. 1866 fn focusVisible(self: *View, index: usize, root_focus: *Focus, last: bool) void { 1867 const inner = self.detailInner(index); 1868 var offset: usize = 0; 1869 while (offset < inner.children.count()) : (offset += 1) { 1870 const child_index = if (last) inner.children.count() - 1 - offset else offset; 1871 if (self.focusVisibleChild(index, child_index, root_focus, last)) return; 1872 } 1873 } 1874 1875 fn focusVisibleChild(self: *View, index: usize, child_index: usize, root_focus: *Focus, last: bool) bool { 1876 const child = &self.detailInner(index).children.values()[child_index]; 1877 const child_rect = child.rect orelse return false; 1878 var chosen: ?usize = null; 1879 if (child.widget.getFocus().focusable and self.detailRectVisible(index, child_rect)) { 1880 const id = self.detailInner(index).children.keys()[child_index]; 1881 chosen = id; 1882 if (!last) { 1883 root_focus.setFocus(id); 1884 return true; 1885 } 1886 } 1887 1888 for (child.widget.getFocus().children.keys(), child.widget.getFocus().children.values()) |id, focus_child| { 1889 if (!focus_child.focus.focusable) continue; 1890 const rect: layout.IRect = .{ 1891 .x = child_rect.x + @as(isize, @intCast(focus_child.rect.x)), 1892 .y = child_rect.y + @as(isize, @intCast(focus_child.rect.y)), 1893 .size = focus_child.rect.size, 1894 }; 1895 if (!self.detailRectVisible(index, rect)) continue; 1896 chosen = id; 1897 if (!last) break; 1898 } 1899 if (chosen) |id| { 1900 root_focus.setFocus(id); 1901 return true; 1902 } 1903 return false; 1904 } 1905 1906 fn focusAdjacentVisible(self: *View, index: usize, root_focus: *Focus, down: bool) bool { 1907 const inner = self.detailInner(index); 1908 var next = self.focusedDetailChild(index, root_focus) orelse return false; 1909 while (true) { 1910 if (down) { 1911 next += 1; 1912 if (next >= inner.children.count()) return false; 1913 } else { 1914 if (next == 0) return false; 1915 next -= 1; 1916 } 1917 if (self.focusVisibleChild(index, next, root_focus, !down)) { 1918 self.focusDetailChild(index, next, !down, root_focus); 1919 return true; 1920 } 1921 } 1922 } 1923 1924 fn focusedDetailChild(self: *View, index: usize, root_focus: *Focus) ?usize { 1925 const inner = self.detailInner(index); 1926 var id = root_focus.grandchild_id orelse return null; 1927 while (inner.getFocus().children.get(id)) |child| { 1928 if (child.parent_id == inner.getFocus().id) return inner.children.getIndex(id); 1929 id = child.parent_id; 1930 } 1931 return null; 1932 } 1933 1934 fn detailChildFocusable(self: *View, index: usize, child_index: usize) bool { 1935 const child = &self.detailInner(index).children.values()[child_index].widget; 1936 const focus = child.getFocus(); 1937 if (focus.focusable) return true; 1938 for (focus.children.values()) |item| { 1939 if (item.focus.focusable) return true; 1940 } 1941 return false; 1942 } 1943 1944 fn focusDetailChild(self: *View, index: usize, child_index: usize, last: bool, root_focus: *Focus) void { 1945 const inner = self.detailInner(index); 1946 const child = &inner.children.values()[child_index]; 1947 var target = inner.children.keys()[child_index]; 1948 var rect = child.rect orelse return; 1949 switch (child.widget) { 1950 .repo_comment => |*comment| { 1951 if (comment.rowRect(last)) |row_rect| { 1952 rect.x += row_rect.x; 1953 rect.y += row_rect.y; 1954 rect.size = row_rect.size; 1955 } 1956 if (last) comment.focusBody(root_focus) else comment.focusMetadata(root_focus); 1957 }, 1958 .box => |*box| if (box.children.count() > 0) { 1959 target = box.children.keys()[if (last) box.children.count() - 1 else 0]; 1960 root_focus.setFocus(target); 1961 }, 1962 else => root_focus.setFocus(target), 1963 } 1964 const sc = self.detailScroll(index); 1965 if (sc.grid) |viewport| { 1966 const viewport_height = viewport.size.height - sc.bar_h; 1967 if (rect.size.height > viewport_height) { 1968 const bottom_aligned = rect.y + @as(isize, @intCast(rect.size.height - viewport_height)); 1969 sc.y = std.math.clamp(sc.y, rect.y, bottom_aligned); 1970 sc.clampToContent(); 1971 return; 1972 } 1973 } 1974 sc.scrollToRect(rect); 1975 } 1976 1977 fn moveDetailVertical(self: *View, index: usize, root_focus: *Focus, down: bool) bool { 1978 const inner = self.detailInner(index); 1979 const current = self.focusedDetailChild(index, root_focus) orelse return false; 1980 if (inner.children.values()[current].widget == .repo_comment) { 1981 const comment = &inner.children.values()[current].widget.repo_comment; 1982 if (down and !comment.bodyFocused()) { 1983 self.focusDetailChild(index, current, true, root_focus); 1984 return true; 1985 } 1986 if (!down and comment.bodyFocused()) { 1987 self.focusDetailChild(index, current, false, root_focus); 1988 return true; 1989 } 1990 } 1991 1992 var next = current; 1993 while (true) { 1994 if (down) { 1995 next += 1; 1996 if (next >= inner.children.count()) return false; 1997 } else { 1998 if (next == 0) return false; 1999 next -= 1; 2000 } 2001 if (!self.detailChildFocusable(index, next)) continue; 2002 self.focusDetailChild(index, next, !down, root_focus); 2003 return true; 2004 } 2005 } 2006 2007 fn moveCommentHorizontal(self: *View, index: usize, root_focus: *Focus, right: bool) bool { 2008 const inner = self.detailInner(index); 2009 const current = self.focusedDetailChild(index, root_focus) orelse return false; 2010 const child = &inner.children.values()[current]; 2011 if (child.widget == .repo_comment) { 2012 const moved = child.widget.repo_comment.moveHorizontal(root_focus, right); 2013 if (moved) if (child.rect) |rect| self.detailScroll(index).scrollToRect(rect); 2014 return moved; 2015 } 2016 const row = switch (child.widget) { 2017 .box => |*box| box, 2018 else => return false, 2019 }; 2020 const selected = row.getFocus().child_id orelse return false; 2021 const selected_index = row.children.getIndex(selected) orelse return false; 2022 const target = if (right) selected_index + 1 else selected_index -| 1; 2023 if (target == selected_index or target >= row.children.count()) return false; 2024 root_focus.setFocus(row.children.keys()[target]); 2025 if (child.rect) |rect| self.detailScroll(index).scrollToRect(rect); 2026 return true; 2027 } 2028 2029 // up/down (and tab/shift+tab) move between a form's fields; up from the 2030 // title crosses into the header tabs. the multiline description keeps 2031 // enter and any up/down that has a row to move to. 2032 fn formInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2033 const form = self.issueForm() orelse return; 2034 const cid = form.getFocus().child_id orelse return; 2035 const cur = form.children.getIndex(cid) orelse return; 2036 2037 if (cur == description_field_index) { 2038 const child = &form.children.values()[cur]; 2039 if (try multilineKeepsKey(&child.widget.text_input, allocator, key)) 2040 return child.widget.input(allocator, key, root_focus); 2041 } 2042 2043 switch (key) { 2044 .arrow_up, .back_tab => if (cur > 0) 2045 root_focus.setFocus(form.children.keys()[cur - 1]) 2046 else 2047 self.focusHeader(root_focus), 2048 .arrow_down, .tab => if (cur < submit_field_index) { 2049 root_focus.setFocus(form.children.keys()[cur + 1]); 2050 }, 2051 .enter => if (cur == submit_field_index) try self.submitForm(allocator), 2052 .mouse => |mouse| if (cur == submit_field_index) { 2053 const submit = &form.children.values()[cur].widget.submit_button; 2054 if (inp.leftClickOn(root_focus, submit.buttonId(), mouse)) try self.submitForm(allocator); 2055 }, 2056 else => try form.children.values()[cur].widget.input(allocator, key, root_focus), 2057 } 2058 } 2059 2060 fn commentFormInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2061 const form = self.issueForm() orelse return; 2062 const cid = form.getFocus().child_id orelse return; 2063 const cur = form.children.getIndex(cid) orelse return; 2064 const child = &form.children.values()[cur]; 2065 2066 if (cur == comment_body_field_index and try multilineKeepsKey(&child.widget.text_input, allocator, key)) 2067 return child.widget.input(allocator, key, root_focus); 2068 2069 switch (key) { 2070 .arrow_up, .back_tab => if (cur > comment_author_field_index) 2071 root_focus.setFocus(form.children.keys()[cur - 1]) 2072 else 2073 self.focusHeader(root_focus), 2074 .arrow_down, .tab => if (cur < comment_submit_field_index) 2075 root_focus.setFocus(form.children.keys()[cur + 1]), 2076 .enter => if (cur == comment_submit_field_index) try self.submitComment(allocator), 2077 .mouse => |mouse| if (cur == comment_submit_field_index) { 2078 const submit = &child.widget.submit_button; 2079 if (inp.leftClickOn(root_focus, submit.buttonId(), mouse)) try self.submitComment(allocator); 2080 }, 2081 else => try child.widget.input(allocator, key, root_focus), 2082 } 2083 } 2084 2085 // the multiline hunk inputs keep enter and any up/down that has a row to 2086 // move to; enter on a "use this" link is a navigation the host follows 2087 // before this runs. 2088 fn resolveInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2089 const form = self.issueForm() orelse return; 2090 const cid = form.getFocus().child_id orelse return; 2091 const cur = form.children.getIndex(cid) orelse return; 2092 const child = &form.children.values()[cur]; 2093 2094 if (child.widget == .text_input) { 2095 const ti = &child.widget.text_input; 2096 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2097 return child.widget.input(allocator, key, root_focus); 2098 } 2099 2100 const on_submit = child.widget == .submit_button; 2101 2102 switch (key) { 2103 .arrow_up, .back_tab => if (resolveStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2104 .arrow_down, .tab => if (resolveStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2105 .arrow_left, .arrow_right => switch (child.widget) { 2106 .box => |*row| { 2107 const row_cid = row.getFocus().child_id orelse return; 2108 const row_index = row.children.getIndex(row_cid) orelse return; 2109 if (key == .arrow_left) { 2110 if (row_index > 0) root_focus.setFocus(row.children.keys()[row_index - 1]); 2111 } else if (row_index + 1 < row.children.count()) { 2112 root_focus.setFocus(row.children.keys()[row_index + 1]); 2113 } 2114 }, 2115 else => try child.widget.input(allocator, key, root_focus), 2116 }, 2117 .enter => if (on_submit) try self.submitResolution(allocator), 2118 .mouse => |mouse| if (on_submit) { 2119 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2120 }, 2121 else => try child.widget.input(allocator, key, root_focus), 2122 } 2123 } 2124 2125 // a multiline input keeps enter and any up/down that has a row to move to 2126 fn multilineKeepsKey(text_input: *wgt.TextInput(ui.Widget), allocator: std.mem.Allocator, key: Key) !bool { 2127 return switch (key) { 2128 .enter => true, 2129 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2130 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2131 else => false, 2132 }; 2133 } 2134 2135 // the neighboring focusable resolve-form child, skipping the spacer and 2136 // the blank gap rows 2137 fn resolveStep(form: *wgt.Box(ui.Widget), cur: usize, down: bool) ?usize { 2138 var i = cur; 2139 while (true) { 2140 if (down) { 2141 i += 1; 2142 if (i >= form.children.count()) return null; 2143 } else { 2144 if (i == 0) return null; 2145 i -= 1; 2146 } 2147 switch (form.children.values()[i].widget) { 2148 .spacer, .text => continue, 2149 else => return i, 2150 } 2151 } 2152 } 2153 2154 // focus the resolve-form child at `i` (a version row focuses its selected 2155 // child) and keep it visible on the terminal 2156 fn focusResolveChild(self: *View, form: *wgt.Box(ui.Widget), i: usize, root_focus: *Focus) void { 2157 const child = &form.children.values()[i]; 2158 switch (child.widget) { 2159 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2160 else => root_focus.setFocus(form.children.keys()[i]), 2161 } 2162 if (self.session.is_terminal) { 2163 if (self.resolveScroll()) |sc| { 2164 if (child.rect) |rect| sc.scrollToRect(rect); 2165 } 2166 } 2167 } 2168 2169 // re-emit the conflicted issue's event with the resolved content; any 2170 // event on the issue settles its conflict entry. this is the terminal 2171 // path; the web posts the form to the resolve route. 2172 fn submitResolution(self: *View, allocator: std.mem.Allocator) !void { 2173 if (comptime wasm) return; 2174 const io = self.session.io orelse return; 2175 const src = self.data.repo_source orelse return; 2176 const entry = self.data.selectedIssue() orelse return; 2177 const author = (try self.session.eventAuthor()) orelse return; 2178 const form = self.issueForm() orelse return; 2179 2180 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2181 var title: ?[]u8 = null; 2182 var tags: ?[]u8 = null; 2183 var hunks: std.ArrayList([]const u8) = .empty; 2184 defer { 2185 if (title) |t| allocator.free(t); 2186 if (tags) |t| allocator.free(t); 2187 for (hunks.items) |h| allocator.free(h); 2188 hunks.deinit(allocator); 2189 } 2190 for (form.children.values()) |*child| switch (child.widget) { 2191 .text_input => |*ti| { 2192 const text = try ti.text(allocator); 2193 errdefer allocator.free(text); 2194 if (std.mem.eql(u8, ti.options.name, "title")) { 2195 title = text; 2196 } else if (std.mem.eql(u8, ti.options.name, "tags")) { 2197 tags = text; 2198 } else { 2199 try hunks.append(allocator, text); 2200 } 2201 }, 2202 else => {}, 2203 }; 2204 2205 var id_bytes: [evt.event_id_size]u8 = undefined; 2206 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2207 2208 switch (src.repo_kind) { 2209 inline else => |repo_kind| { 2210 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2211 defer any_repo.deinit(io, allocator); 2212 switch (any_repo) { 2213 inline else => |*repo| evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .resolve = .{ 2214 .title = title, 2215 .tags = tags, 2216 .hunks = hunks.items, 2217 } }, author) catch |err| switch (err) { 2218 // leave the form up for correction 2219 error.InvalidFields => return, 2220 else => |e| return e, 2221 }, 2222 } 2223 }, 2224 } 2225 2226 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, entry.issue.event.status, "", entry.id) orelse return; 2227 try self.session.navigate(route); 2228 } 2229 2230 // commit a new or edited comment and navigate to its permalink. this is the 2231 // terminal path; the web posts the form to its comment route. 2232 fn submitComment(self: *View, allocator: std.mem.Allocator) !void { 2233 if (comptime wasm) return; 2234 const io = self.session.io orelse return; 2235 const src = self.data.repo_source orelse return; 2236 const author = (try self.session.eventAuthor()) orelse return; 2237 const form = self.issueForm() orelse return; 2238 const body_input = &form.children.values()[comment_body_field_index].widget.text_input; 2239 const body = try body_input.text(allocator); 2240 defer allocator.free(body); 2241 if (!evt.Comment.fieldsValid(body)) return; 2242 2243 var thread_id: [evt.event_id_size * 2]u8 = undefined; 2244 @memcpy(&thread_id, self.data.selected_id); 2245 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 2246 var parent: [evt.event_id_size * 2]u8 = undefined; 2247 @memcpy(&parent, self.data.comment_id); 2248 break :blk parent; 2249 }; 2250 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 2251 const editing = self.data.view == .edit_comment; 2252 switch (src.repo_kind) { 2253 inline else => |repo_kind| { 2254 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2255 defer any_repo.deinit(io, allocator); 2256 switch (any_repo) { 2257 inline else => |*repo| if (editing) { 2258 var comment_id: [evt.event_id_size]u8 = undefined; 2259 _ = std.fmt.hexToBytes(&comment_id, self.data.comment_id) catch return; 2260 try evt.Comment.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &comment_id, body, author); 2261 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 2262 } else { 2263 event_id_hex = try evt.Comment.create(repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &parent_id, body, author); 2264 }, 2265 } 2266 }, 2267 } 2268 2269 body_input.clear(allocator); 2270 const route = ui.RoutablePage.repoCommentsRoute(self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 2271 try self.session.navigate(route); 2272 } 2273 2274 // the terminal submit paths: the new form commits a new-issue event, the 2275 // edit form re-emits the selected issue's event with the form's content. 2276 // the web posts the forms to their routes instead. 2277 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 2278 if (self.data.view == .edit) { 2279 try self.submitEditedIssue(allocator); 2280 } else { 2281 try self.submitNewIssue(allocator); 2282 } 2283 } 2284 2285 // commit the new issue to the repo's events branch and navigate to it. 2286 // this is the terminal path; the web posts the form to the issue route, 2287 // so the wasm side never runs (or compiles) the repo access below. 2288 fn submitNewIssue(self: *View, allocator: std.mem.Allocator) !void { 2289 if (comptime wasm) return; 2290 const io = self.session.io orelse return; 2291 const src = self.data.repo_source orelse return; 2292 const author = (try self.session.eventAuthor()) orelse return; 2293 2294 const form = self.issueForm() orelse return; 2295 const title_input = &form.children.values()[title_field_index].widget.text_input; 2296 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 2297 const description_input = &form.children.values()[description_field_index].widget.text_input; 2298 2299 const title = try title_input.text(allocator); 2300 defer allocator.free(title); 2301 const tags = try tags_input.text(allocator); 2302 defer allocator.free(tags); 2303 const description = try description_input.text(allocator); 2304 defer allocator.free(description); 2305 2306 if (!evt.Issue.fieldsValid(title, tags)) return; 2307 2308 var id_bytes: [evt.event_id_size]u8 = undefined; 2309 io.random(&id_bytes); 2310 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 2311 2312 const event = evt.EventWithId{ 2313 .id = event_id_hex, 2314 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 2315 .author = author, 2316 .event = .{ .issue = .{ 2317 .title = title, 2318 .description = description, 2319 .tags = tags, 2320 } }, 2321 }; 2322 2323 switch (src.repo_kind) { 2324 inline else => |repo_kind| { 2325 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2326 defer any_repo.deinit(io, allocator); 2327 switch (any_repo) { 2328 inline else => |*repo| try evt.consume(repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 2329 } 2330 }, 2331 } 2332 2333 // wipe the form so a return visit starts fresh 2334 title_input.clear(allocator); 2335 tags_input.clear(allocator); 2336 description_input.clear(allocator); 2337 2338 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, .open, "", &event_id_hex) orelse return; 2339 try self.session.navigate(route); 2340 } 2341 2342 // re-emit the selected issue's event with the form's content (status 2343 // preserved), then reload the issue's page. this is the terminal path; 2344 // the web posts the form to the edit route. 2345 fn submitEditedIssue(self: *View, allocator: std.mem.Allocator) !void { 2346 if (comptime wasm) return; 2347 const io = self.session.io orelse return; 2348 const src = self.data.repo_source orelse return; 2349 const entry = self.data.selectedIssue() orelse return; 2350 const author = (try self.session.eventAuthor()) orelse return; 2351 2352 const form = self.issueForm() orelse return; 2353 const title_input = &form.children.values()[title_field_index].widget.text_input; 2354 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 2355 const description_input = &form.children.values()[description_field_index].widget.text_input; 2356 2357 const title = try title_input.text(allocator); 2358 defer allocator.free(title); 2359 const tags = try tags_input.text(allocator); 2360 defer allocator.free(tags); 2361 const description = try description_input.text(allocator); 2362 defer allocator.free(description); 2363 2364 if (!evt.Issue.fieldsValid(title, tags)) return; 2365 2366 var id_bytes: [evt.event_id_size]u8 = undefined; 2367 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2368 2369 switch (src.repo_kind) { 2370 inline else => |repo_kind| { 2371 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2372 defer any_repo.deinit(io, allocator); 2373 switch (any_repo) { 2374 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2375 .title = title, 2376 .tags = tags, 2377 .description = description, 2378 } }, author), 2379 } 2380 }, 2381 } 2382 2383 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, entry.issue.event.status, "", entry.id) orelse return; 2384 try self.session.navigate(route); 2385 } 2386 2387 // flip the shown issue's status by re-emitting its event, then reload the 2388 // page rooted at the issue so the view reflects the change. this is the 2389 // terminal path; the web posts the button's form to the status route. 2390 fn toggleIssueStatus(self: *View, allocator: std.mem.Allocator, index: usize) !void { 2391 if (comptime wasm) return; 2392 const io = self.session.io orelse return; 2393 const src = self.data.repo_source orelse return; 2394 const sel = self.detailed_index[index] orelse return; 2395 const entry = self.window(index).issues[sel]; 2396 const author = (try self.session.eventAuthor()) orelse return; 2397 2398 const status: evt.Issue.Status = switch (entry.issue.event.status) { 2399 .open => .closed, 2400 .closed => .open, 2401 }; 2402 2403 var id_bytes: [evt.event_id_size]u8 = undefined; 2404 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2405 2406 switch (src.repo_kind) { 2407 inline else => |repo_kind| { 2408 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2409 defer any_repo.deinit(io, allocator); 2410 switch (any_repo) { 2411 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2412 } 2413 }, 2414 } 2415 2416 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, status, "", entry.id) orelse return; 2417 try self.session.navigate(route); 2418 } 2419 2420 // arrow keys move the tag selection; at the flow's edges focus crosses to 2421 // the neighboring widgets. 2422 fn tagsInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 2423 const tf = self.tagFlow(index) orelse return; 2424 const cid = tf.focus.child_id orelse return; 2425 const cur = tf.indexOfFocusId(cid) orelse return; 2426 const count = tf.text_boxes.items.len; 2427 switch (key) { 2428 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 2429 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 2430 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2431 self.focusTag(index, tf, root_focus, i); 2432 } else { 2433 _ = self.moveDetailVertical(index, root_focus, false); 2434 }, 2435 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2436 self.focusTag(index, tf, root_focus, i); 2437 } else { 2438 _ = self.moveDetailVertical(index, root_focus, true); 2439 }, 2440 .home => self.focusTag(index, tf, root_focus, 0), 2441 .end => self.focusTag(index, tf, root_focus, count - 1), 2442 else => {}, 2443 } 2444 } 2445 2446 const title_child_index: usize = 0; 2447 const tags_child_index: usize = 2; 2448 2449 // the tool row's first child after the spacer that pushes it right 2450 const first_in_row_index: usize = 1; 2451 2452 fn tagFlow(self: *View, index: usize) ?*ui.TagFlow { 2453 const inner = self.detailInner(index); 2454 if (inner.children.count() <= tags_child_index) return null; 2455 return switch (inner.children.values()[tags_child_index].widget) { 2456 .tag_flow => |*tf| tf, 2457 else => null, 2458 }; 2459 } 2460 2461 fn tagsFocused(self: *View, index: usize) bool { 2462 const inner = self.detailInner(index); 2463 const cid = inner.getFocus().child_id orelse return false; 2464 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 2465 } 2466 2467 fn toolRowFocused(self: *View, index: usize) bool { 2468 const outer = self.detailOuter(index); 2469 const cid = outer.getFocus().child_id orelse return false; 2470 return outer.children.getIndex(cid) == tool_row_index; 2471 } 2472 2473 fn focusTag(self: *View, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2474 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2475 // keep the tag visible on the terminal: its rect offset by the flow's 2476 // position in the pane. 2477 if (self.session.is_terminal and item < tf.rects.items.len) { 2478 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 2479 var rect = tf.rects.items[item]; 2480 rect.x += flow_rect.x; 2481 rect.y += flow_rect.y; 2482 self.detailScroll(index).scrollToRect(rect); 2483 } 2484 } 2485 } 2486 2487 fn titleFocused(self: *View, index: usize) bool { 2488 const inner = self.detailInner(index); 2489 const cid = inner.getFocus().child_id orelse return false; 2490 return inner.children.getIndex(cid) == title_child_index; 2491 } 2492 2493 fn authorFocused(self: *View, index: usize) bool { 2494 const inner = self.detailInner(index); 2495 const cid = inner.getFocus().child_id orelse return false; 2496 return cid == self.author_id[index]; 2497 } 2498 2499 fn descriptionFocused(self: *View, index: usize) bool { 2500 const cid = self.detailInner(index).getFocus().child_id orelse return false; 2501 return cid == self.description_id[index]; 2502 } 2503 2504 // return to the tool row's last-focused button (the header when the 2505 // description page shows no row). 2506 fn focusToolRow(self: *View, index: usize, root_focus: *Focus) void { 2507 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2508 root_focus.setFocus(cid); 2509 } 2510 2511 // enter the detail pane. an empty pane (no issues) can't be entered. 2512 fn focusDetail(self: *View, index: usize, root_focus: *Focus) !void { 2513 if (self.detailInner(index).children.count() == 0) return; 2514 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2515 } 2516 2517 // return to the list. 2518 fn focusList(self: *View, index: usize, root_focus: *Focus) !void { 2519 root_focus.setFocus(self.listScroll(index).getFocus().id); 2520 } 2521 2522 // cross to the header tabs above the stack. 2523 fn focusHeader(self: *View, root_focus: *Focus) void { 2524 root_focus.setFocus(self.box.children.keys()[header_index]); 2525 } 2526 2527 pub fn clearGrid(self: *View) void { 2528 self.box.clearGrid(); 2529 } 2530 2531 pub fn getGrid(self: View) ?Grid { 2532 return self.box.getGrid(); 2533 } 2534 2535 pub fn getFocus(self: *View) *Focus { 2536 return self.box.getFocus(); 2537 } 2538 2539 // for the parent's "scroll up at the top jumps to the header" check: at the 2540 // top only while the header tabs hold focus, so up from the split 2541 // crosses into the tabs first. 2542 pub fn getSelectedIndex(self: *View) ?usize { 2543 return if (self.headerActive()) 0 else 1; 2544 } 2545 }; 2546 2547 // the "a:" navigation link for `status`'s issues page filtered to the 2548 // url-encoded `tag` and rooted at issue `id` within `identity` ("owner/name"). 2549 // a rooted url ignores `status` (it derives its view from the issue's own); 2550 // with an empty `id` this is the bare list link. 2551 fn issuesLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8, id: []const u8) ![]const u8 { 2552 const route = ui.RoutablePage.repoIssuesRoute(identity, status, tag, id) orelse return error.RouteTooLong; 2553 const url = try route.toUrl(page_arena); 2554 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2555 } 2556 2557 // the in-page "ai:" anchor for selecting issue `id` in `identity`'s list; the 2558 // href is only followed with js off. 2559 fn issueRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2560 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; 2561 const url = try route.toUrl(page_arena); 2562 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 2563 } 2564 2565 // the "a:" link to the window `status_maybe` names, keeping the tag filter, 2566 // or the conflicts window when null, rooted at issue `id`. 2567 fn windowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, status_maybe: ?evt.Issue.Status, id: []const u8) ![]const u8 { 2568 if (status_maybe) |status| return issuesLink(page_arena, data.identity, status, data.tag, id); 2569 return conflictsLink(page_arena, data.identity, id); 2570 } 2571 2572 // the "a:" link to the conflicts list rooted at issue `start` ("" = the 2573 // first window). 2574 fn conflictsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, start: []const u8) ![]const u8 { 2575 const route = ui.RoutablePage.repoIssuesConflictsRoute(identity, start) orelse return error.RouteTooLong; 2576 const url = try route.toUrl(page_arena); 2577 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2578 } 2579 2580 // the "a:" link to the whole-description page of issue `id` within `identity`. 2581 fn descriptionLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2582 const route = ui.RoutablePage.repoIssuesDescriptionRoute(identity, id) orelse return error.RouteTooLong; 2583 const url = try route.toUrl(page_arena); 2584 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2585 } 2586 2587 // the "a:" link to `status`'s issues list filtered to `tag` (raw; encoded here). 2588 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8) ![]const u8 { 2589 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 2590 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 2591 const url = try route.toUrl(page_arena); 2592 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2593 } 2594 2595 // tabs switching between the issues page's views. 2596 pub const Header = struct { 2597 box: wgt.Box(ui.Widget), 2598 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 2599 2600 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 2601 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 2602 errdefer box.deinit(allocator); 2603 2604 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 2605 errdefer tab_ids.deinit(allocator); 2606 2607 const aa = session.page_arena.allocator(); 2608 2609 // a list tab per status, labeled with its listing's issue count 2610 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 2611 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 2612 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2613 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 2614 try addTab(allocator, &box, &tab_ids, label, link); 2615 } 2616 2617 // tags tab, labeled with the active tag filter 2618 { 2619 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 2620 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 2621 const label = if (data.tag.len == 0) "tags" else blk: { 2622 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 2623 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 2624 }; 2625 try addTab(allocator, &box, &tab_ids, label, tags_link); 2626 } 2627 2628 // new-issue tab; an edit or resolve url shows its tab in this place 2629 { 2630 const route = switch (data.view) { 2631 .edit => ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 2632 .new_comment => ui.RoutablePage.repoCommentNewRoute(data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 2633 .edit_comment => ui.RoutablePage.repoCommentEditRoute(data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 2634 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 2635 else => ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong, 2636 }; 2637 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2638 const label: []const u8 = switch (data.view) { 2639 .edit => "edit", 2640 .new_comment => "reply", 2641 .edit_comment => "edit", 2642 .resolve => "resolve", 2643 else => "new", 2644 }; 2645 try addTab(allocator, &box, &tab_ids, label, link); 2646 } 2647 2648 // conflicts tab, labeled with the conflict count 2649 if (data.conflicts.count > 0) { 2650 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 2651 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2652 const label = try std.fmt.allocPrint(aa, "conflicts ({d})", .{data.conflicts.count}); 2653 try addTab(allocator, &box, &tab_ids, label, link); 2654 } 2655 2656 var self = Header{ .box = box, .tab_ids = tab_ids }; 2657 // the tab matching the page's view is selected initially. 2658 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 2659 return self; 2660 } 2661 2662 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 2663 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 2664 errdefer text_box.deinit(allocator); 2665 text_box.getFocus().focusable = true; 2666 text_box.getFocus().kind = .{ .custom = link }; 2667 try tab_ids.put(allocator, text_box.getFocus().id, {}); 2668 try box.children.put(allocator, text_box.getFocus().id, .{ 2669 .widget = .{ .text_box = text_box }, 2670 .rect = null, 2671 .min_size = .{ .width = label.len + 2, .height = null }, 2672 }); 2673 } 2674 2675 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 2676 self.box.deinit(allocator); 2677 self.tab_ids.deinit(allocator); 2678 } 2679 2680 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2681 self.clearGrid(); 2682 // only the selected tab shows its border 2683 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 2684 switch (child.widget) { 2685 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 2686 else => {}, 2687 } 2688 } 2689 try self.box.build(allocator, constraint, root_focus); 2690 } 2691 2692 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2693 _ = allocator; 2694 const current_tab = self.currentTabIndex() orelse return; 2695 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 2696 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 2697 } 2698 } 2699 2700 pub fn clearGrid(self: *Header) void { 2701 self.box.clearGrid(); 2702 } 2703 2704 pub fn getGrid(self: Header) ?Grid { 2705 return self.box.getGrid(); 2706 } 2707 2708 pub fn getFocus(self: *Header) *Focus { 2709 return self.box.getFocus(); 2710 } 2711 2712 pub fn getSelectedIndex(self: Header) ?usize { 2713 return self.currentTabIndex(); 2714 } 2715 2716 fn currentTabIndex(self: Header) ?usize { 2717 const child_id = self.box.focus.child_id orelse return null; 2718 return self.tab_ids.getIndex(child_id); 2719 } 2720 }; 2721