X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/feda522eba3e2a27c91741c77d0d01f1840c0004..09cde69fdffe2721434392036f98dc241177f5a1:/view.go?ds=inline diff --git a/view.go b/view.go index 3ccf87e..a75b1d8 100644 --- a/view.go +++ b/view.go @@ -41,8 +41,8 @@ type nodeReader interface { // For the sibling pair (l, i) and (l, i+1), due is (T - last) / 2^l, with T the // number of messages and last the ID of the last message of the pair. That is // how long ago the pair ended, measured in its own line size. With a budget of -// the length of Taelin's rollback push list, this order makes the same merges -// as the push. The oldest pair wins a tie. +// the length of the rollback push list of the reference design, this order +// makes the same merges as the push. The oldest pair wins a tie. type View struct { high int low int @@ -280,15 +280,25 @@ func (v *View) lineSize(line nodeKey) int { // Render returns the view as the model reads it: one line "id+n|text" for each // node inside tags, with the newlines of the text as spaces. func (v *View) Render() string { - var text strings.Builder - text.WriteString("\n") + return "\n" + strings.Join(v.LinesWithout(nil), "") + "" +} + +// LinesWithout returns the lines of the view as the model reads them, each with +// its newline, without the leaf lines of the messages in skip. A line that +// merges such a message with others stays. +func (v *View) LinesWithout(skip map[int]bool) []string { + lines := make([]string, 0, len(v.lines)) for _, line := range v.lines { + if line.level == 0 && skip[line.index] { + continue + } + + var text strings.Builder v.renderLine(&text, line) + lines = append(lines, text.String()) } - text.WriteString("") - - return text.String() + return lines } // renderLine writes one view line, "id+n|text", and a newline.