diff --git a/CHANGELOG.md b/CHANGELOG.md index 26671be48..0ba0af19b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - **The Pulls screen is redrawn, and its list is sorted by what each pull request needs.** Open ones are grouped into Ready to merge, Needs work, In review and Drafts, in place of the All, Ready, Drafts and Failing filters and the Approved state. Inside a pull request, its facts stand beside the description, and Copy link and Copy Markdown are in the `⋯` menu. +- **Review threads in Pulls show who answers whom.** Each thread is a card with its file and code, and its replies hang from a line under the comment they answer, in Conversation and between the lines in Files. - **Long conversations no longer slow the window down.** Scrolling, typing and watching an answer come in cost about the same in a chat of thousands of messages as in a new one, and several agents working at once take about a third of the processor they took. Answers also come in more smoothly, about thirty updates a second instead of twenty. diff --git a/native/DESIGN.md b/native/DESIGN.md index 215544e9e..1f62ccb2a 100644 --- a/native/DESIGN.md +++ b/native/DESIGN.md @@ -95,7 +95,7 @@ look on every page (`browser_notes_view.go`), and Windows' close button hovers i | --- | --- | | `Canvas` | the ground the islands float on | | `Background` | full screens inside the stage (Settings, Pulls) and code blocks set inside a raised surface | -| `Sidebar`, `Card`, `Popover` | islands and raised parts: sidebar, dock, a code or log island and the box being written in on Pulls, menus, dialogs | +| `Sidebar`, `Card`, `Popover` | islands and raised parts: sidebar, dock, a code or log island and a thread's card on Pulls, menus, dialogs | | `Accent` | hover and selection fill | | `MutedForeground` | secondary text, icons at rest, paths, meta, the tree's links and neutral rings | | `Border` | input edges and the island hairline | @@ -1070,12 +1070,18 @@ right. No card, rule or zebra separates the rows; a group is a muted uppercase h (`factLine`): branches, conflicts, checks, a reviewer with what they said, the sessions and checkout it has here. A fact it does not have is left out, never "none". A narrow island puts the facts on top. Editing swaps the description for its box with the text where the prose was, and the facts stay still. -- **Conversation** has no boxes around what was said: an avatar, the name and age, the text under them. A thread is - a folding line with its file over its code, the lines it is about in an edged `Sidebar` island, then its talk. A - comment's own actions are in a `⋯` under the pointer. Only the box being written in is filled (`writeBox`), - with `Textarea.Bare` inside it, so the one surface on the page is where the keyboard is. -- **Files** gives each file a header on the `Background` and its code in an edged `Sidebar` island under it, where - its threads sit between the lines. The dock's Review keeps the header inside the card. +- **Conversation** has no box around what is said to everyone: an avatar, the name and age, the text under them. What + is said about a file's lines is a card where that text starts (`talkCard`): edged, on `Sidebar`, its head the + file, the lines, the folder and the fold (folded, what the thread opens with), then the code from edge to edge and + the talk at `Space(3)`. A reply stands in by an avatar, on a line from the first comment's that turns into each one + (`replyTree`, in the sidebar tree's stroke) and ends at the last. Reply is a field at rest under the talk, not a + node of that line, with Send to session and Resolve at its right. The comments of a review not sent yet are cards + of the same shape, and so is the box for a comment on the pull request. An entry's own actions are in a `⋯` under + the pointer. A box being written in (`writeBox`) has no field in it, `Textarea.Bare`, and is filled with what it + does not stand on: `Sidebar` on the screen, `Background` in a card. +- **Files** gives each file a header on the `Background` and its code in an edged `Sidebar` island under it. Its + threads, pending comments and the box writing one are the conversation's cards between the lines, without the file + in their head. The dock's Review keeps the header inside the card. - **Checks** are grouped Failed, Running and Passed. A finished job opens its log in the same tab (`pulls_log.go`): the checks stay in a column at the left under All checks, and the log is an edged `Sidebar` island at the right, its steps (GitLab's has none) folding lines with the failed one open and scrolled to its first error. The log's text is mono @@ -1100,7 +1106,7 @@ right. No card, rule or zebra separates the rows; a group is a muted uppercase h says nothing. A draft is muted, on a list row and in the head alike, since amber on a row is the verdict waiting on its reviewer. - **Actions** stand at the right. In a comment, reply or edit box, Cancel then the action, which wears Ctrl+Enter's cap (`ctrlEnterCap`, Cmd+Enter on macOS) or `↵`'s where Enter sends. A thread's are ghost `SizeXS` - after its talk: Send to session, then Resolve, which folds it away. A pending comment's Edit and Discard are the + beside its reply field: Send to session, then Resolve, which folds it away. A pending comment's Edit and Discard are the same small neutral ghosts: what Discard drops was never sent. - **A pull request linked by hand** (`linkpr_panel.go`): the session's card menu has Link pull request…, a `DropdownPanel` (`Space(75)` wide) with one field for `#N` or a GitHub or GitLab URL, Cancel (ghost) and a @@ -1509,8 +1515,9 @@ space, never a rule. ### Boxes inside a screen -A thread, a pending comment or a composer is a box on `Sidebar` with `RadiusMD` and `Space(3)` padding. Its -children draw on `th.On(th.Sidebar)`. +A pending comment or a composer is a box on `Sidebar` with `RadiusMD` and `Space(3)` padding. Its children draw on +`th.On(th.Sidebar)`. On Pulls they and the threads are its cards (see Pulls › Conversation), where the lines a thread +is about are a diff from edge to edge and its comments stand `Space(4)` apart. A notice about the box's own session (the usage limit's) is a balloon in the composer's head, over the text: `Space(2)` from the box's edge, `RadiusMD` inside the box's `RadiusLG`, filled with the box's own fill mixed toward diff --git a/native/cmd/lich-native/dock_comments.go b/native/cmd/lich-native/dock_comments.go index c731f5616..89a75a53f 100644 --- a/native/cmd/lich-native/dock_comments.go +++ b/native/cmd/lich-native/dock_comments.go @@ -267,7 +267,7 @@ func (c *commentComposer) write(gtx C, th *ui.Theme, store *commentStore, target return D{} } action, prompt, keys := c.words() - return writeBox{editor: &c.editor, placeholder: prompt, action: action, keys: keys, send: &c.add, cancel: &c.cancel}.layout(gtx, th) + return inlineCard(gtx, th, writeBox{editor: &c.editor, placeholder: prompt, action: action, keys: keys, send: &c.add, cancel: &c.cancel, plain: true}.layout) } // layout draws the box while open; it is zero-sized when closed. diff --git a/native/cmd/lich-native/pulls_comment_edit.go b/native/cmd/lich-native/pulls_comment_edit.go index 3cbbc834c..98bb8d38f 100644 --- a/native/cmd/lich-native/pulls_comment_edit.go +++ b/native/cmd/lich-native/pulls_comment_edit.go @@ -99,11 +99,7 @@ func (v *pullView) comment(gtx C, th *ui.Theme, p *pullsScreen, t commentTarget, over.read(gtx) dims := p.withAvatar(gtx, th, who, func(gtx C) D { children := []layout.FlexChild{layout.Rigid(func(gtx C) D { - gtx.Constraints.Min.Y = gtx.Dp(authorAvatarSize) - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Flexed(1, ui.Spanning(head)), - layout.Rigid(func(gtx C) D { return v.commentMore(gtx, th, p, t, over.over) }), - ) + return entryHead(gtx, head, func(gtx C) D { return v.commentMore(gtx, th, p, t, over.over) }) })} if content != nil { children = append(children, ui.VGap(0.5), layout.Rigid(content)) @@ -133,10 +129,7 @@ func (v *pullView) commentMore(gtx C, th *ui.Theme, p *pullsScreen, t commentTar return th.DropdownMenu(p.root, menu, entries).Layout(gtx, func(gtx C) D { b := th.Button(clickableOf(s.moreClicks, t.key()), "") b.Icon, b.Variant, b.Size = icPullMore, ui.VariantGhost, ui.SizeIconXS - // No taller than the name's line, which it must not move. - dims := v.withTip(gtx, th, p, "more:"+t.key(), i18n.T("pulls.reviewThread.more"), b.Layout) - dims.Size.Y = min(dims.Size.Y, gtx.Dp(authorAvatarSize)) - return dims + return v.withTip(gtx, th, p, "more:"+t.key(), i18n.T("pulls.reviewThread.more"), b.Layout) }) } diff --git a/native/cmd/lich-native/pulls_conversation.go b/native/cmd/lich-native/pulls_conversation.go index 7faac7803..c26395244 100644 --- a/native/cmd/lich-native/pulls_conversation.go +++ b/native/cmd/lich-native/pulls_conversation.go @@ -1,7 +1,6 @@ package main import ( - "path/filepath" "strings" "time" @@ -141,14 +140,19 @@ func (v *pullView) conversationRows(gtx C, th *ui.Theme, p *pullsScreen, d backe target := commentTarget{kind: prComment, id: c.ID, body: c.Body, canEdit: c.CanEdit, canDelete: c.CanDelete} rows = append(rows, v.talkEntry(th, p, "comment:"+c.Date+c.Author, author{c.Author, c.Avatar}, "", target, c.Date, now, act)) default: - rows = append(rows, v.threadRow(th, p, d, *it.thread, act, now, 0)) + row := v.threadRow(th, p, d, *it.thread, act, now) + if len(rows) == 0 { + card := row + row = func(gtx C) D { return layout.Inset{Top: talkGap}.Layout(gtx, card) } + } + rows = append(rows, row) } } if len(resolved) > 0 { rows = append(rows, func(gtx C) D { return v.resolvedToggle(gtx, th, len(resolved)) }) if v.talk.showResolved.Value { for _, t := range resolved { - rows = append(rows, v.threadRow(th, p, d, t, act, now, pullsTextX-pullsPadX)) + rows = append(rows, v.threadRow(th, p, d, t, act, now)) } } } @@ -208,17 +212,19 @@ func byline(gtx C, th *ui.Theme, author, verdict, date string, now time.Time) D return layout.Flex{Alignment: layout.Baseline}.Layout(gtx, children...) } -// resolvedToggle is the line that folds the resolved threads. +// resolvedToggle is the line that folds the resolved threads, over their cards. func (v *pullView) resolvedToggle(gtx C, th *ui.Theme, n int) D { s := &v.talk label := i18n.T("pulls.pullsConversation.resolved", i18n.Args{"count": n}) gtx.Constraints.Max.X = min(gtx.Constraints.Max.X, gtx.Dp(overviewProseWidth+2*pullsPadX)) - return pullsLine(gtx, th, &s.resolvedTap, false, func(gtx C, th *ui.Theme) D { - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(inNodeColumn(func(gtx C) D { return foldIcon(s.showResolved.Value).Layout(gtx, ui.Space(3.5), th.MutedForeground) })), - layout.Rigid(layout.Spacer{Width: pullsLineGap}.Layout), - layout.Rigid(th.Text(ui.TextSM, label).Muted().Layout), - ) + return layout.Inset{Left: pullsTextX, Right: pullsPadX}.Layout(gtx, func(gtx C) D { + return th.NavRow(gtx, &s.resolvedTap, false, pullsLineHeight, cardPad, func(gtx C, th *ui.Theme) D { + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, + layout.Rigid(inNodeColumn(func(gtx C) D { return foldIcon(s.showResolved.Value).Layout(gtx, ui.Space(3.5), th.MutedForeground) })), + layout.Rigid(layout.Spacer{Width: pullsLineGap}.Layout), + layout.Rigid(th.Text(ui.TextSM, label).Muted().Layout), + ) + }) }) } @@ -236,83 +242,79 @@ func (v *pullView) commentBox(gtx C, th *ui.Theme, act *pullsAction) D { } box := writeBox{editor: &s.comment, placeholder: i18n.T("pulls.pullsConversation.commentOn"), action: i18n.T("pulls.pullsConversation.comment"), send: &s.commentSend, cancel: &s.commentDrop, busy: v.busyNow() == "comment", - resting: s.comment.Len() == 0 && !gtx.Focused(&s.comment)} + plain: true, resting: s.comment.Len() == 0 && !gtx.Focused(&s.comment)} if box.busy { box.action = i18n.T("pulls.commentBox.sending") } - return talkColumn(gtx, func(gtx C) D { - return layout.Inset{Top: talkGap, Bottom: talkGap}.Layout(gtx, func(gtx C) D { return box.layout(gtx, th) }) - }) + return layout.Inset{Top: talkGap, Bottom: 2 * talkGap}.Layout(gtx, func(gtx C) D { return talkCardRow(gtx, th, box.layout) }) } -// pendingRows is the review being written: each line comment as an entry of -// the viewer's own, until the review is submitted. +// pendingRows is the review being written: each line comment as a card of the +// viewer's own, until the review is submitted. func (v *pullView) pendingRows(th *ui.Theme, p *pullsScreen, r *pendingReview) []layout.Widget { comments := r.snapshot() rows := make([]layout.Widget, len(comments)) for i, c := range comments { rows[i] = func(gtx C) D { - return talkColumn(gtx, func(gtx C) D { return v.pendingEntry(gtx, th, p, i, c) }) + return talkCardRow(gtx, th, func(gtx C, th *ui.Theme) D { + return layout.Flex{Axis: layout.Vertical}.Layout(gtx, + layout.Rigid(func(gtx C) D { return pendingHead(gtx, th, c) }), + layout.Rigid(func(gtx C) D { + return layout.Inset{Left: cardPad, Right: cardPad, Bottom: cardPad}.Layout(gtx, func(gtx C) D { return v.pendingEntry(gtx, th, p, i, c) }) + }), + ) + }) } } return rows } +// pendingHead is where a pending comment is, as a thread's card names it. +func pendingHead(gtx C, th *ui.Theme, c backend.ReviewComment) D { + gtx.Constraints.Min.Y = gtx.Dp(cardHeadHeight) + return layout.Inset{Left: cardPad, Right: cardPad}.Layout(gtx, func(gtx C) D { + return layout.W.Layout(gtx, func(gtx C) D { + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, append(cardFile(th, c.Path), + layout.Rigid(th.Text(ui.TextXS, lineAnchor(c.StartLine, c.Line)).Mono().Layout))...) + }) + }) +} + // pendingEntry is one line comment of the review being written, with Edit and -// Discard beside the line it is on, or the box rewording it. +// Discard, or the box rewording it. func (v *pullView) pendingEntry(gtx C, th *ui.Theme, p *pullsScreen, i int, c backend.ReviewComment) D { + s := &v.talk + e := &s.pendingEdit + editing := e.open && e.index == i you := author{login: i18n.T("pulls.pullsConversation.you")} + who := func(gtx C) D { + return byline(gtx, th, you.login, i18n.T("pulls.pullsConversation.pendingNote"), "", gtx.Now) + } + actions := func(gtx C) D { + if editing { + return D{} + } + edit := th.Button(clickableAt(s.edits, i), i18n.T("pulls.pullsConversation.edit")) + edit.Size, edit.Variant = ui.SizeXS, ui.VariantGhost + discard := th.Button(clickableAt(s.discards, i), i18n.T("pulls.pullsConversation.discard")) + discard.Size, discard.Variant = ui.SizeXS, ui.VariantGhost + return layout.Flex{}.Layout(gtx, layout.Rigid(edit.Layout), ui.Gap(1), layout.Rigid(discard.Layout)) + } + body := th.Text(ui.TextSM, c.Body).Wrapped().Layout + if editing { + body = func(gtx C) D { + return writeBox{editor: &e.editor, action: i18n.T("pulls.pullsConversation.save"), send: &e.save, cancel: &e.cancel}.layout(gtx, th) + } + } return p.withAvatar(gtx, th, you, func(gtx C) D { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, - layout.Rigid(func(gtx C) D { - gtx.Constraints.Min.Y = gtx.Dp(authorAvatarSize) - return layout.W.Layout(gtx, func(gtx C) D { - return byline(gtx, th, you.login, i18n.T("pulls.pullsConversation.pendingNote"), "", gtx.Now) - }) - }), + layout.Rigid(func(gtx C) D { return entryHead(gtx, who, actions) }), ui.VGap(0.5), - layout.Rigid(func(gtx C) D { - return v.pendingBody(gtx, th, i, c, func(gtx C) D { return fileAnchor(gtx, th, c.Path, lineAnchor(c.StartLine, c.Line)) }) - }), + layout.Rigid(body), ) }) } -// pendingBody is a pending comment's text over where, what says where it -// stands, and its Edit and Discard; or the box rewording it. -func (v *pullView) pendingBody(gtx C, th *ui.Theme, i int, c backend.ReviewComment, where layout.Widget) D { - s := &v.talk - if e := &s.pendingEdit; e.open && e.index == i { - return writeBox{editor: &e.editor, action: i18n.T("pulls.pullsConversation.save"), send: &e.save, cancel: &e.cancel}.layout(gtx, th) - } - edit := th.Button(clickableAt(s.edits, i), i18n.T("pulls.pullsConversation.edit")) - edit.Size, edit.Variant = ui.SizeXS, ui.VariantGhost - discard := th.Button(clickableAt(s.discards, i), i18n.T("pulls.pullsConversation.discard")) - discard.Size, discard.Variant = ui.SizeXS, ui.VariantGhost - return layout.Flex{Axis: layout.Vertical}.Layout(gtx, - layout.Rigid(th.Text(ui.TextSM, c.Body).Wrapped().Layout), - ui.VGap(1), - layout.Rigid(func(gtx C) D { - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Flexed(1, ui.Spanning(where)), - ui.Gap(2), layout.Rigid(edit.Layout), - ui.Gap(1), layout.Rigid(discard.Layout), - ) - }), - ) -} - -// fileAnchor is a file's icon and name with the lines a comment is on. -func fileAnchor(gtx C, th *ui.Theme, path, lines string) D { - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(th.FileIcon(path, ui.Space(3.5)).Layout), - ui.Gap(1.5), - layout.Rigid(th.Text(ui.TextXS, filepath.Base(path)).Weight(font.Medium).Layout), - ui.Gap(1.5), - layout.Rigid(th.Text(ui.TextXS, lines).Mono().Muted().Layout), - ) -} - func (v *pullView) pendingOf(url string) *pendingReview { r, ok := v.pending[url] if !ok { diff --git a/native/cmd/lich-native/pulls_files.go b/native/cmd/lich-native/pulls_files.go index e50483de6..464b28273 100644 --- a/native/cmd/lich-native/pulls_files.go +++ b/native/cmd/lich-native/pulls_files.go @@ -395,22 +395,27 @@ func (v *pullView) inlineThread(gtx C, id string) D { if len(t.Comments) > 0 { t.Comments[0].DiffHunk = "" } - return threadSlot.Layout(gtx, func(gtx C) D { return v.threadInline(gtx, f.th.On(f.th.Sidebar), t) }) + return inlineCard(gtx, f.th, func(gtx C, th *ui.Theme) D { return v.threadInline(gtx, th, t) }) } return D{} } -// threadSlot is the room a thread or a pending comment keeps in the diff. -var threadSlot = layout.Inset{Left: ui.Space(3), Right: ui.Space(3), Top: ui.Space(2.5), Bottom: ui.Space(2.5)} +// inlineCard is a card between the diff's lines, at the conversation's width. +func inlineCard(gtx C, th *ui.Theme, w func(gtx C, th *ui.Theme) D) D { + return layout.Inset{Left: ui.Space(3), Right: ui.Space(3), Top: ui.Space(2.5), Bottom: ui.Space(2.5)}.Layout(gtx, func(gtx C) D { + gtx.Constraints.Max.X = min(gtx.Constraints.Max.X, gtx.Dp(overviewProseWidth)) + return talkCard(gtx, th, w) + }) +} -// threadInline is a thread on the code's own surface: what was said, under the -// line that folds it once it is resolved or folded. +// threadInline is a thread's card in the diff: what was said, under the line +// that folds it once it is resolved or folded. func (v *pullView) threadInline(gtx C, th *ui.Theme, t backend.PRReviewThread) D { f := v.inline open := v.threadOpen(gtx, t) talk := func(gtx C) D { return v.threadTalk(gtx, th, f.p, f.d, t, f.act, f.now) } if open && !t.IsResolved { - return talk(gtx) + return cardInset.Layout(gtx, talk) } fact := threadFact(f.p, t, open) if t.IsResolved { @@ -418,15 +423,15 @@ func (v *pullView) threadInline(gtx C, th *ui.Theme, t backend.PRReviewThread) D } return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { - return th.NavRow(gtx, v.talk.foldClicks[t.ID], false, pullsLineHeight, 0, func(gtx C, th *ui.Theme) D { - return threadLine(gtx, th, t, open, fact, false) + return th.NavRow(gtx, v.talk.foldClicks[t.ID], false, cardHeadHeight, cardPad, func(gtx C, th *ui.Theme) D { + return threadHead(gtx, th, t, open, fact, false) }) }), layout.Rigid(func(gtx C) D { if !open { return D{} } - return layout.Inset{Top: ui.Space(1)}.Layout(gtx, talk) + return layout.Inset{Left: cardPad, Right: cardPad, Bottom: cardPad}.Layout(gtx, talk) }), ) } @@ -434,7 +439,7 @@ func (v *pullView) threadInline(gtx C, th *ui.Theme, t backend.PRReviewThread) D // inlinePending is a comment waiting for the review to be submitted, with // the Conversation tab's Edit and Discard: talkClicks carries them out. func (v *pullView) inlinePending(gtx C, i int, c backend.ReviewComment) D { - th := v.inline.th.On(v.inline.th.Sidebar) - note := th.Text(ui.TextXS, i18n.T("pulls.pullsConversation.pendingNote")).In(th.ToneWait).Layout - return threadSlot.Layout(gtx, func(gtx C) D { return v.pendingBody(gtx, th, i, c, note) }) + return inlineCard(gtx, v.inline.th, func(gtx C, th *ui.Theme) D { + return cardInset.Layout(gtx, func(gtx C) D { return v.pendingEntry(gtx, th, v.inline.p, i, c) }) + }) } diff --git a/native/cmd/lich-native/pulls_talk_card.go b/native/cmd/lich-native/pulls_talk_card.go new file mode 100644 index 000000000..2d66dd2cf --- /dev/null +++ b/native/cmd/lich-native/pulls_talk_card.go @@ -0,0 +1,129 @@ +package main + +import ( + "image" + "path" + + "gioui.org/f32" + "gioui.org/font" + "gioui.org/layout" + "gioui.org/op" + "gioui.org/op/clip" + "gioui.org/op/paint" + + "github.com/lichdotdev/lich/native/ui" +) + +// What is said about a file's lines is a card on the Pulls screen, the same in +// the conversation and between a diff's lines. +var ( + cardPad = ui.Space(3) + cardInset = layout.UniformInset(cardPad) + cardHeadHeight = ui.Space(9) + // replyGap is the room between a thread's comments. + replyGap = ui.Space(4) + // replyElbow is the turn of the line into a reply. + replyElbow = ui.Space(2) + // replyAir is what the line keeps off the avatars it joins. + replyAir = ui.Space(1) +) + +// talkCard is w in an edged box on Sidebar, as wide as it is given and as tall +// as w. +func talkCard(gtx C, th *ui.Theme, w func(gtx C, th *ui.Theme) D) D { + gtx.Constraints.Min = image.Pt(gtx.Constraints.Max.X, 0) + on := th.On(th.Sidebar) + record := op.Record(gtx.Ops) + dims := w(gtx, on) + draw := record.Stop() + r := gtx.Dp(ui.RadiusLG) + box := clip.UniformRRect(image.Rectangle{Max: dims.Size}, r).Push(gtx.Ops) + paint.Fill(gtx.Ops, on.Surface) + draw.Add(gtx.Ops) + box.Pop() + ui.IslandBorder(gtx, dims.Size, r, on.Over(on.Border)) + return dims +} + +// talkCardRow is a card of the conversation, closer to the entry it follows +// and to the next card than two entries are. +func talkCardRow(gtx C, th *ui.Theme, w func(gtx C, th *ui.Theme) D) D { + gtx.Constraints.Max.X = min(gtx.Constraints.Max.X, gtx.Dp(overviewProseWidth+2*pullsPadX)) + return layout.Inset{Left: pullsTextX, Right: pullsPadX, Top: ui.Space(0.5), Bottom: ui.Space(1.5)}.Layout(gtx, func(gtx C) D { return talkCard(gtx, th, w) }) +} + +// cardFile names the file a card is about, its icon over the avatars under it. +func cardFile(th *ui.Theme, file string) []layout.FlexChild { + return []layout.FlexChild{ + layout.Rigid(inNodeColumn(th.FileIcon(file, ui.Space(3.5)).Layout)), + layout.Rigid(layout.Spacer{Width: authorAvatarGap}.Layout), + layout.Rigid(th.Text(ui.TextSM, path.Base(file)).Weight(font.Medium).Layout), + ui.Gap(2), + } +} + +// replyTree is a thread's comments: the one that opens it, and the others in +// by an avatar, each on the line down from the first one's. +func replyTree(gtx C, th *ui.Theme, entries []layout.Widget) D { + indent, width := gtx.Dp(authorAvatarSize+authorAvatarGap), gtx.Constraints.Max.X + var replies []int + y := 0 + for i, entry := range entries { + x := 0 + if i > 0 { + x = indent + y += gtx.Dp(replyGap) + replies = append(replies, y) + } + g := gtx + room := max(width-x, 0) + g.Constraints = layout.Constraints{Min: image.Pt(room, 0), Max: image.Pt(room, gtx.Constraints.Max.Y)} + at := op.Offset(image.Pt(x, y)).Push(gtx.Ops) + y += entry(g).Size.Y + at.Pop() + } + replyLinks(gtx, th, replies) + return D{Size: image.Pt(width, y)} +} + +// replyLinks draws the line from the first comment's avatar into each reply +// that starts at tops, in the sidebar tree's stroke. +func replyLinks(gtx C, th *ui.Theme, tops []int) { + if len(tops) == 0 { + return + } + size, air, elbow := gtx.Dp(authorAvatarSize), gtx.Dp(replyAir), float32(gtx.Dp(replyElbow)) + x, end := float32(size)/2, float32(gtx.Dp(authorAvatarSize+authorAvatarGap)-air) + last := tops[len(tops)-1] + size + links := []linkSeg{vline(x, float32(size+air), float32(last)-x-elbow)} + for _, top := range tops { + mid := float32(top) + x + links = append(links, func(p *clip.Path) { + p.MoveTo(f32.Pt(x, mid-elbow)) + p.QuadTo(f32.Pt(x, mid), f32.Pt(x+elbow, mid)) + p.LineTo(f32.Pt(end, mid)) + }) + } + strokeLinks(gtx, links, image.Pt(int(end), last), th.Over(ui.Alpha(th.MutedForeground, treeLinkAlpha)), float32(gtx.Dp(sessionTreeStroke))) +} + +// entryHead is the line beside an avatar: who, and end at its end, neither +// making it taller than the avatar. +func entryHead(gtx C, who, end layout.Widget) D { + line := gtx.Dp(authorAvatarSize) + centred := func(w layout.Widget) layout.Widget { + return func(gtx C) D { + gtx.Constraints.Min.Y = 0 + record := op.Record(gtx.Ops) + dims := w(gtx) + draw := record.Stop() + defer op.Offset(image.Pt(0, (line-dims.Size.Y)/2)).Push(gtx.Ops).Pop() + draw.Add(gtx.Ops) + return D{Size: image.Pt(dims.Size.X, line)} + } + } + return layout.Flex{}.Layout(gtx, + layout.Flexed(1, ui.Spanning(centred(who))), + layout.Rigid(centred(end)), + ) +} diff --git a/native/cmd/lich-native/pulls_talk_card_test.go b/native/cmd/lich-native/pulls_talk_card_test.go new file mode 100644 index 000000000..dfbbbae0a --- /dev/null +++ b/native/cmd/lich-native/pulls_talk_card_test.go @@ -0,0 +1,79 @@ +package main + +import ( + "image" + "slices" + "testing" + + "gioui.org/layout" + "gioui.org/op" + + "github.com/lichdotdev/lich/native/i18n" + "github.com/lichdotdev/lich/native/ui" +) + +// A reply stands in by an avatar, under the comment that opens its thread, and +// takes the width left. +func TestRepliesStandInFromTheCommentTheyAnswer(t *testing.T) { + gtx := layout.Context{Ops: new(op.Ops), Constraints: layout.Constraints{Max: image.Pt(400, 1000)}} + var widths []int + entry := func(height int) layout.Widget { + return func(gtx C) D { + widths = append(widths, gtx.Constraints.Max.X) + return D{Size: image.Pt(gtx.Constraints.Max.X, height)} + } + } + in := gtx.Dp(authorAvatarSize + authorAvatarGap) + for _, c := range []struct { + name string + talk []layout.Widget + widths []int + height int + }{ + {"one comment", []layout.Widget{entry(40)}, []int{400}, 40}, + {"two replies", []layout.Widget{entry(40), entry(60), entry(30)}, []int{400, 400 - in, 400 - in}, 130 + 2*gtx.Dp(replyGap)}, + } { + t.Run(c.name, func(t *testing.T) { + widths = nil + got := replyTree(gtx, testTheme().On(ui.Dark.Sidebar), c.talk) + if got.Size != image.Pt(400, c.height) { + t.Errorf("size = %v, want 400x%d", got.Size, c.height) + } + if !slices.Equal(widths, c.widths) { + t.Errorf("widths = %v, want %v", widths, c.widths) + } + }) + } +} + +// Whatever stands beside the avatar, its line is as tall as the avatar: the ⋯ +// that shows under the pointer moves nothing. +func TestEntryHeadIsAsTallAsTheAvatar(t *testing.T) { + gtx := layout.Context{Ops: new(op.Ops), Constraints: layout.Constraints{Max: image.Pt(400, 1000)}} + tall := func(h int) layout.Widget { return func(gtx C) D { return D{Size: image.Pt(24, h)} } } + for _, end := range []int{0, 24} { + if got := entryHead(gtx, tall(20), tall(end)).Size; got != image.Pt(400, gtx.Dp(authorAvatarSize)) { + t.Errorf("with %d at its end the line is %v", end, got) + } + } +} + +// The field under a thread is where its reply is written: a click opens the +// box in its place, Cancel puts it back. +func TestClickingTheReplyFieldOpensTheBox(t *testing.T) { + u, r := pullsFrames(t) + u.pulls.openPR(7) + waitFor(t, "the pull request", func() bool { r.frame(); return u.pulls.store.conversation("/repo", 7).val != nil }) + u.pulls.view.tabs.Selected = int(tabConversation) + r.frame() + r.clickLabel(t, i18n.T("pulls.reviewThread.reply")) + r.frame() + if !u.pulls.view.talk.replying["T1"] { + t.Fatal("the click opened no box") + } + r.clickLabel(t, i18n.T("common.action.cancel")) + r.frame() + if u.pulls.view.talk.replying["T1"] { + t.Error("Cancel left the box open") + } +} diff --git a/native/cmd/lich-native/pulls_thread.go b/native/cmd/lich-native/pulls_thread.go index 568713d25..bcc78c781 100644 --- a/native/cmd/lich-native/pulls_thread.go +++ b/native/cmd/lich-native/pulls_thread.go @@ -8,9 +8,7 @@ import ( "strings" "time" - "gioui.org/font" "gioui.org/layout" - "gioui.org/unit" "github.com/lichdotdev/lich/native/backend" "github.com/lichdotdev/lich/native/i18n" @@ -18,30 +16,28 @@ import ( "github.com/lichdotdev/lich/native/ui/codeview" ) -// threadRow is a thread in the conversation, indent in from its column: the -// line that folds it, then its code and what was said, both where the line's -// text starts. -func (v *pullView) threadRow(th *ui.Theme, p *pullsScreen, d backend.PRDetail, t backend.PRReviewThread, act *pullsAction, now time.Time, indent unit.Dp) layout.Widget { +// threadRow is a thread in the conversation: a card where the entries' text +// starts, its head over its code and what was said. +func (v *pullView) threadRow(th *ui.Theme, p *pullsScreen, d backend.PRDetail, t backend.PRReviewThread, act *pullsAction, now time.Time) layout.Widget { return func(gtx C) D { - gtx.Constraints.Max.X = min(gtx.Constraints.Max.X, gtx.Dp(overviewProseWidth+2*pullsPadX)) open := v.threadOpen(gtx, t) - return layout.Inset{Left: indent}.Layout(gtx, func(gtx C) D { + return talkCardRow(gtx, th, func(gtx C, th *ui.Theme) D { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { - return pullsLine(gtx, th, v.talk.foldClicks[t.ID], false, func(gtx C, th *ui.Theme) D { - return threadLine(gtx, th, t, open, threadFact(p, t, open), true) + return th.NavRow(gtx, v.talk.foldClicks[t.ID], false, cardHeadHeight, cardPad, func(gtx C, th *ui.Theme) D { + return threadHead(gtx, th, t, open, threadFact(p, t, open), true) }) }), layout.Rigid(func(gtx C) D { if !open { return D{} } - return layout.Inset{Left: pullsTextX, Right: pullsPadX, Top: ui.Space(1), Bottom: ui.Space(3)}.Layout(gtx, func(gtx C) D { - return layout.Flex{Axis: layout.Vertical}.Layout(gtx, - layout.Rigid(func(gtx C) D { return v.threadCode(gtx, th, p, t) }), - layout.Rigid(func(gtx C) D { return v.threadTalk(gtx, th, p, d, t, act, now) }), - ) - }) + return layout.Flex{Axis: layout.Vertical}.Layout(gtx, + layout.Rigid(func(gtx C) D { return v.threadCode(gtx, th, p, t) }), + layout.Rigid(func(gtx C) D { + return cardInset.Layout(gtx, func(gtx C) D { return v.threadTalk(gtx, th, p, d, t, act, now) }) + }), + ) }), ) }) @@ -77,26 +73,14 @@ func threadFact(p *pullsScreen, t backend.PRReviewThread, open bool) string { return "" } -// threadLine is where a thread is: its file, named where the diff around it +// threadHead is where a thread is: its file, named where the diff around it // does not already, and its lines; then the folder, or folded what the thread -// opens with. -func threadLine(gtx C, th *ui.Theme, t backend.PRReviewThread, open bool, fact string, file bool) D { +// opens with; the fold at the end. +func threadHead(gtx C, th *ui.Theme, t backend.PRReviewThread, open bool, fact string, file bool) D { start := t.StartLine if start == t.Line { start = 0 } - children := []layout.FlexChild{ - layout.Rigid(inNodeColumn(func(gtx C) D { return foldIcon(open).Layout(gtx, ui.Space(3.5), th.MutedForeground) })), - layout.Rigid(layout.Spacer{Width: pullsLineGap}.Layout), - } - if file { - children = append(children, - layout.Rigid(th.FileIcon(t.Path, ui.Space(3.5)).Layout), - ui.Gap(1.5), - layout.Rigid(th.Text(ui.TextSM, path.Base(t.Path)).Weight(font.Medium).Layout), - ui.Gap(1.5), - ) - } rest := layout.Widget(layout.Spacer{}.Layout) switch dir := path.Dir(t.Path); { case !open && len(t.Comments) > 0: @@ -104,32 +88,35 @@ func threadLine(gtx C, th *ui.Theme, t backend.PRReviewThread, open bool, fact s case open && file && dir != ".": rest = th.Text(ui.TextXS, dir).Mono().Muted().Layout } + var children []layout.FlexChild + if file { + children = cardFile(th, t.Path) + } return layout.Flex{Alignment: layout.Middle}.Layout(gtx, append(children, layout.Rigid(th.Text(ui.TextXS, lineAnchor(start, t.Line)).Mono().Layout), ui.Gap(2), layout.Flexed(1, ui.Spanning(rest)), ui.Gap(2), layout.Rigid(th.Text(ui.TextXS, fact).Muted().Layout), + ui.Gap(2), + layout.Rigid(func(gtx C) D { return foldIcon(open).Layout(gtx, ui.Space(3.5), th.MutedForeground) }), )...) } -// threadTalk is what was said in the thread, then Reply, Send to session and -// Resolve, gone while one of its comments is edited. +// threadTalk is what was said in the thread, the replies on the line from the +// comment that opens it, then Reply, Send to session and Resolve, gone while +// one of its comments is edited. func (v *pullView) threadTalk(gtx C, th *ui.Theme, p *pullsScreen, d backend.PRDetail, t backend.PRReviewThread, act *pullsAction, now time.Time) D { - var rows []layout.FlexChild editing := false - for _, c := range t.Comments { + entries := make([]layout.Widget, len(t.Comments)) + for i, c := range t.Comments { target := threadTarget(t, c) editing = v.talk.isEditing(gtx, target) || editing - if len(rows) > 0 { - rows = append(rows, ui.VGap(3)) - } - rows = append(rows, layout.Rigid(func(gtx C) D { return v.threadComment(gtx, th, p, target, c, act, now) })) + entries[i] = func(gtx C) D { return v.threadComment(gtx, th, p, target, c, act, now) } } + rows := []layout.FlexChild{layout.Rigid(func(gtx C) D { return replyTree(gtx, th, entries) })} if !editing { - rows = append(rows, ui.VGap(2), layout.Rigid(func(gtx C) D { - return layout.Inset{Left: authorAvatarSize + authorAvatarGap}.Layout(gtx, func(gtx C) D { return v.threadActions(gtx, th, p, d, t, act) }) - })) + rows = append(rows, ui.VGap(4), layout.Rigid(func(gtx C) D { return v.threadActions(gtx, th, p, d, t, act) })) } return layout.Flex{Axis: layout.Vertical}.Layout(gtx, rows...) } @@ -184,8 +171,8 @@ func threadPatch(file, hunk string) string { return fmt.Sprintf("--- a/%s\n+++ b/%s\n@@ -%d,%d +%d,%d @@\n%s\n", file, file, from, old, to, new, strings.Join(lines[cut:], "\n")) } -// threadCode is the lines the thread is about, as the Files tab draws them, on -// an island of their own. +// threadCode is the lines the thread is about, as the Files tab draws them, +// from edge to edge of the thread's card. func (v *pullView) threadCode(gtx C, th *ui.Theme, p *pullsScreen, t backend.PRReviewThread) D { if len(t.Comments) == 0 || t.Comments[0].DiffHunk == "" || v.files == nil { return D{} @@ -205,20 +192,13 @@ func (v *pullView) threadCode(gtx C, th *ui.Theme, p *pullsScreen, t backend.PRR log.Printf("thread code: %v", err) return D{} } - pad, height := gtx.Dp(ui.Space(1)), code.files[0].rows*cell - gtx.Constraints = layout.Exact(image.Pt(gtx.Constraints.Max.X, height+2*pad)) - dims := pullsIsland(gtx, th, th.Sidebar, func(gtx C, th *ui.Theme) D { - return layout.Inset{Top: ui.Space(1), Left: 1, Right: 1}.Layout(gtx, func(gtx C) D { - gtx.Constraints.Min = image.Point{} - return code.files[0].layout(gtx, th, codeview.OnSurface(th, p.files.code), height) - }) - }) - dims.Size.Y += gtx.Dp(ui.Space(3.5)) - return dims + height := code.files[0].rows * cell + gtx.Constraints = layout.Exact(image.Pt(gtx.Constraints.Max.X, height)) + return code.files[0].layout(gtx, th, codeview.OnSurface(th, p.files.code), height) } -// threadActions is Reply at the start and, at the end, Send to session and -// Resolve; or the box while a reply is written. +// threadActions is the reply's field at rest and, at the end, Send to session +// and Resolve; or the box while a reply is written. func (v *pullView) threadActions(gtx C, th *ui.Theme, p *pullsScreen, d backend.PRDetail, t backend.PRReviewThread, act *pullsAction) D { s := &v.talk reply, resolve := clickableOf(s.replyClicks, t.ID), clickableOf(s.resolveClick, t.ID) @@ -244,21 +224,31 @@ func (v *pullView) threadActions(gtx C, th *ui.Theme, p *pullsScreen, d backend. } resolveB.Variant, resolveB.Size, resolveB.Disabled = ui.VariantGhost, ui.SizeXS, v.busyNow() == "resolve:"+t.ID return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(func(gtx C) D { - return reply.Layout(gtx, func(gtx C) D { - label := th.Text(ui.TextSM, i18n.T("pulls.reviewThread.reply")).Muted() - if reply.Hovered() { - label = label.In(th.Foreground) - } - return label.Layout(gtx) - }) - }), - layout.Flexed(1, func(gtx C) D { return D{Size: image.Pt(gtx.Constraints.Min.X, 0)} }), + layout.Flexed(1, func(gtx C) D { return replyField(gtx, th, reply) }), + ui.Gap(2), layout.Rigid(func(gtx C) D { return v.toSessionButton(gtx, th, p, d, t, act) }), ui.Gap(1), layout.Rigid(resolveB.Layout)) } +// replyField is the box a reply is written in before it is: one line, as wide +// as the actions leave it. +func replyField(gtx C, th *ui.Theme, click *ui.Clickable) D { + return click.Layout(gtx, func(gtx C) D { + on := th.On(th.Background) + label := on.Text(ui.TextSM, i18n.T("pulls.reviewThread.reply")).Muted() + if click.Hovered() { + label = label.In(on.Foreground) + } + return layout.Background{}.Layout(gtx, + func(gtx C) D { return ui.Fill(gtx, on.Surface, ui.RadiusMD) }, + func(gtx C) D { + return layout.Inset{Left: ui.Space(2.5), Right: ui.Space(2.5), Top: ui.Space(1.5), Bottom: ui.Space(1.5)}.Layout(gtx, ui.Spanning(label.Layout)) + }, + ) + }) +} + // toSessionButton is Send to session, Open in Session while the branch's // checkout has no session; nothing on a thread that cannot go. func (v *pullView) toSessionButton(gtx C, th *ui.Theme, p *pullsScreen, d backend.PRDetail, t backend.PRReviewThread, act *pullsAction) D { diff --git a/native/cmd/lich-native/pulls_write.go b/native/cmd/lich-native/pulls_write.go index 4a5506be0..3ef769350 100644 --- a/native/cmd/lich-native/pulls_write.go +++ b/native/cmd/lich-native/pulls_write.go @@ -13,7 +13,7 @@ import ( ) var ( - writeBoxPadX = ui.Space(3.5) + writeBoxPadX = cardPad writeBoxPadY = ui.Space(3) // writeBoxMax is how tall the text grows before it scrolls. writeBoxMax = unit.Dp(320) @@ -32,20 +32,30 @@ type writeBox struct { keys string // the action's key, Ctrl+Enter when "" // resting is the box before it is written in: one line and no buttons. resting bool + // plain is a box that is all its card holds: the card is its fill. + plain bool } func (b writeBox) layout(gtx C, th *ui.Theme) D { gtx.Constraints.Min.X = gtx.Constraints.Max.X - on := th.On(th.Sidebar) + ground := th.Sidebar + if th.Surface == th.Sidebar && !b.plain { + ground = th.Background + } + on := th.On(ground) ta := on.Textarea(b.editor, b.placeholder) ta.Bare, ta.Disabled = true, b.busy ta.PadX, ta.PadY, ta.MaxHeight = writeBoxPadX, writeBoxPadY, writeBoxMax + radius := ui.RadiusLG + if ground == th.Background { + radius = ui.RadiusMD + } children := []layout.FlexChild{layout.Rigid(ta.Layout)} if !b.resting { children = append(children, layout.Rigid(func(gtx C) D { return b.buttons(gtx, on) })) } return layout.Background{}.Layout(gtx, - func(gtx C) D { return ui.Fill(gtx, on.Surface, ui.RadiusLG) }, + func(gtx C) D { return ui.Fill(gtx, on.Surface, radius) }, func(gtx C) D { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, children...) }, ) }